将 SQL 查询转换为 IBatis/MyBatis 查询

Converting SQL Query to IBatis/MyBatis Query

我是 Ibatis 的新手,仍在学习中。我遇到了这个 SQL 查询,需要将其转换为 Ibatis 查询。

我尝试放入 CDATA 标签并尝试了一些迭代器标签,但对我来说没有用。这是我的查询:

SELECT comp_small_name
FROM table_company
WHERE companyid IN (
        SELECT agentid
        FROM (
            SELECT *
            FROM table_comp_price
            WHERE companyid = #compid#
            ORDER BY companyid DESC
            WHERE ROWNUM <= 2
            )
        )

这适用于 Oracle 数据库。

Method 1

SELECT comp_small_name
    FROM table_company
    WHERE companyid IN (
            SELECT agentid
            FROM (
                SELECT *
                FROM table_comp_price
                WHERE companyid = #compid
                ORDER BY companyid DESC
                WHERE <![CDATA[ ROWNUM <= 2 ]]>
                )
            )

或者您也可以使用如下 Method 2:

 SELECT comp_small_name
    FROM table_company
    WHERE companyid IN (
            SELECT agentid
            FROM (
                SELECT *
                FROM table_comp_price
                WHERE companyid = #compid
                ORDER BY companyid DESC
                WHERE ROWNUM &lt;= 2
                )
            )