我的环境
org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3
org.mybatis:mybatis:3.5.5
Oracle version: Oracle Database 12c Release 12.2.0.1.0
有一个表(TBL_TEST
),数据:
ip s_id
---------------------
127.0.0.1 1
127.0.0.1 2
127.0.0.1 3
在 Oracle 数据库中执行 SQL
SELECT
ip,
xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids
FROM TBL_TEST t group by ip
结果
ip s_ids
-------------------------
127.0.0.1 1|2|3|
但是当我使用Mybatis时:
<select id="groupByIp" resultMap="IpConfig">
select
ip,
xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids
from TBL_TEST t group by ip
</select>
它得到错误:
### Error querying database. Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 47, line 3, column 29, token IDENTIFIER s_id : select
ip,
xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids
from TBL_TEST t group by ip
### The error occurred while executing a query
### SQL: select ip, xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids from TBL_TEST t group by ip
### Cause: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 47, line 3, column 29, token IDENTIFIER s_id : select
ip,
xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids
from TBL_TEST t group by ip
; uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 47, line 3, column 29, token IDENTIFIER s_id : select
ip,
xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids
from TBL_TEST t group by ip; nested exception is java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER pos 47, line 3, column 29, token IDENTIFIER s_id : select
ip,
xmlagg(xmlparse(content s_id||'|') order by s_id).getclobval() s_ids
from TBL_TEST t group by ip
如何解决?