oracle中用interval做时间偏移。druid的解析器无法解析。sql大概如下示例:
SELECT *
FROM
XXX
WHERE
LAST_UPDATE_DATE >= to_timestamp('2021-08-10 15:30:00:120', 'yyyy-mm-dd hh24:mi:ss') - INTERVAL '2 min'
AND LAST_UPDATE_DATE < to_timestamp('2021-08-10 15:40:00:090', 'yyyy-mm-dd hh24:mi:ss')
报错如下:
com.alibaba.druid.sql.parser.ParserException: illegal interval type. pos 385, line 19, column 4, token AND
at com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser.parseInterval(OracleExprParser.java:1022)
at com.alibaba.druid.sql.parser.SQLExprParser.primary(SQLExprParser.java:994)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser.primary(OracleExprParser.java:494)
at com.alibaba.druid.sql.parser.SQLExprParser.bitXor(SQLExprParser.java:129)
at com.alibaba.druid.sql.parser.SQLExprParser.multiplicative(SQLExprParser.java:225)
at com.alibaba.druid.sql.parser.SQLExprParser.additiveRest(SQLExprParser.java:2826)
at com.alibaba.druid.sql.parser.SQLExprParser.additive(SQLExprParser.java:2796)
at com.alibaba.druid.sql.parser.SQLExprParser.shift(SQLExprParser.java:2836)
at com.alibaba.druid.sql.parser.SQLExprParser.bitAnd(SQLExprParser.java:2583)
at com.alibaba.druid.sql.parser.SQLExprParser.bitOr(SQLExprParser.java:2602)
at com.alibaba.druid.sql.parser.SQLExprParser.relationalRest(SQLExprParser.java:3217)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser.relationalRest(OracleExprParser.java:1121)
at com.alibaba.druid.sql.parser.SQLExprParser.exprRest(SQLExprParser.java:119)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser.exprRest(OracleExprParser.java:1317)
at com.alibaba.druid.sql.parser.SQLSelectParser.parseWhere(SQLSelectParser.java:686)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleSelectParser.query(OracleSelectParser.java:291)
at com.alibaba.druid.sql.parser.SQLSelectParser.query(SQLSelectParser.java:374)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleSelectParser.select(OracleSelectParser.java:51)
at com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser.parseStatementList(OracleStatementParser.java:95)
at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:565)
at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:559)
at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:582)
2条答案
按热度按时间dzjeubhm1#
看了一下源码,做interval解析时,interval后接一个字符串会尝试去解析OracleIntervalType,没有处理上面的这种情况
owfi6suc2#
我也遇到了这个问题,我的数据库是Mysql。
sql大概如下:
select
GD.LIMIT_DAYS,
GD.LIMIT_CNT,
DATE_FORMAT(DATE_ADD(SI.TRAN_DATE, INTERVAL (-1 * GD.LIMIT_DAYS) + 1 DAY), '%Y%m%d') AS STAND_DATE
报错如下:
java.sql.SQLException: sql injection violation, dbType mysql, , druid-version 1.2.9, syntax error: syntax error, expect ), actual IDENTIFIER pos 649, line 16, column 74, token IDENTIFIER DAY :
com.alibaba.druid.sql.parser.ParserException: syntax error, expect ), actual IDENTIFIER pos 649, line 16, column 74, token IDENTIFIER DAY
at com.alibaba.druid.sql.parser.SQLExprParser.accept(SQLExprParser.java:4567)
at com.alibaba.druid.sql.parser.SQLExprParser.methodRest(SQLExprParser.java:1909)
at com.alibaba.druid.sql.parser.SQLExprParser.primaryRest(SQLExprParser.java:1604)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser.primaryRest(MySqlExprParser.java:751)
at com.alibaba.druid.sql.parser.SQLExprParser.primary(SQLExprParser.java:1314)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser.primary(MySqlExprParser.java:493)
at com.alibaba.druid.sql.parser.SQLExprParser.expr(SQLExprParser.java:96)
at com.alibaba.druid.sql.parser.SQLExprParser.exprList(SQLExprParser.java:2151)
at com.alibaba.druid.sql.parser.SQLExprParser.methodRest(SQLExprParser.java:1831)
at com.alibaba.druid.sql.parser.SQLExprParser.parseSelectItem(SQLExprParser.java:6235)
at com.alibaba.druid.sql.parser.SQLSelectParser.parseSelectList(SQLSelectParser.java:1049)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:238)
at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:61)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.parseTableSource(MySqlSelectParser.java:355)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.parseFrom(MySqlSelectParser.java:100)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:250)
at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:61)
at com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseSelect(MySqlStatementParser.java:124)
at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:213)
at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:125)
at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:630)
at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:584)
at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:830)