Oracle XMLDB的XMLCAST和XMLQUERY与iBatis不兼容?

时间:2010-06-08 09:05:54

标签: oracle ibatis xmltype

我一直在尝试从存储在一个XML中的XML中选择一个值列表 XMLType列,但我不断收到列出的错误 这篇文章的尾部。

选择ID是

getXMLFragment

,以及相关的子集 sqlmap.xml如下:

<select id="getXMLFragment" resultClass="list">
               SELECT
                   XMLCAST(XMLQUERY('$CUSTOMER/CUSTOMER/DETAILS/
CUST_NAME/text()' PASSING CUSTOMER AS
                       "CUSTOMER" RETURNING CONTENT) AS VARCHAR2(20))
AS customers FROM SHOP.CLIENT_INFO
</select>

(CUSTOMER是CLIENT_INFO中的XMLType列)

我用

调用语句
List<String> custNames= (List<String>)
sqlMap.queryForList("getXMLFragment");

我正在使用ibatis-2.3.4.726.jar。

是因为iBatis无法识别XMLDB查询,因此, 错误地标记字符串?在旁注中,我已经实施了 XMLTypeCallback.java成功处理XMLType插入,我 如果我希望检索整个XML,我认为它会起作用。然而, 在这种情况下,我需要仅提取单个值 要求。非常感谢解决方法。

提前致谢。

生成的例外情况如下:

--- The error occurred in sqlMap.xml.
--- The error occurred while preparing the mapped statement for
execution.
--- Check the getXMLFragment.
--- Check the SQL statement.
--- Cause: java.util.NoSuchElementException
       at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:
204)
       at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:
139)
       at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:
567)
       at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:
541)
       at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:
118)
       at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:
122)
       at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:
98)
       at Main.main(Main.java:60)
Caused by: java.util.NoSuchElementException
       at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
       at
com.ibatis.sqlmap.engine.mapping.sql.simple.SimpleDynamicSql.processDynamicElements(SimpleDynamicSql.java:
90)
       at
com.ibatis.sqlmap.engine.mapping.sql.simple.SimpleDynamicSql.getSql(SimpleDynamicSql.java:
45)
       at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:
184)
       ... 7 more

1 个答案:

答案 0 :(得分:0)

更新:我们只需要重复一次'$',以使sql是“ .... XMLQUERY('$$ CUSTOMER .....”),此后令牌化工作正常,并且查询成功执行。