我试图从我的数据库查询一些数据,这是我的SQL代码,它在控制台运行顺利:
select BTN_NAME as btnName,
LAST_EXEC_TIME as lastExecTime,
LAST_EXEC_PARAM as lastExecParam
from BTN_FUNC_FLOW_CTRL
where BTN_NAME = 'REG_FILE_COLLECT' AND LAST_EXEC_TIME >= (SYSTIMESTAMP - INTERVAL '60' MINUTE);
但是当我在mybatis中编写这个sql并执行的时候,出了点问题,我得到了一个ORA-00907
<select id="getByBtnName" resultType="xxx.BtnFuncFlowCtrl">
select BTN_NAME as btnName,
LAST_EXEC_TIME as lastExecTime,
LAST_EXEC_PARAM as lastExecParam
from regulatory.BTN_FUNC_FLOW_CTRL
where BTN_NAME = #{btnName} and LAST_EXEC_TIME >= (SYSTIMESTAMP - INTERVAL #{execInterval} MINUTE);
</select>
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis
### The error may exist in file [C:\Users\Administrator\IdeaProjects\xxx\BtnFuncFlowCtrlMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select BTN_NAME as btnName, LAST_EXEC_TIME as lastExecTime, LAST_EXEC_PARAM as lastExecParam from regulatory.BTN_FUNC_FLOW_CTRL where BTN_NAME = ? and LAST_EXEC_TIME >= (SYSTIMESTAMP - INTERVAL ? MINUTE);
### Cause: java.sql.SQLSyntaxErrorException: ORA-00907:missing right parenthesis
当我去掉括号,我得到了一个ORA-00933
<select id="getByBtnName" resultType="xxx.BtnFuncFlowCtrl">
select BTN_NAME as btnName,
LAST_EXEC_TIME as lastExecTime,
LAST_EXEC_PARAM as lastExecParam
from regulatory.BTN_FUNC_FLOW_CTRL
where BTN_NAME = #{btnName} and LAST_EXEC_TIME >= SYSTIMESTAMP - INTERVAL #{execInterval} MINUTE;
</select>
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
### The error may exist in file [C:\Users\Administrator\IdeaProjects\xxx\BtnFuncFlowCtrlMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select BTN_NAME as btnName, LAST_EXEC_TIME as lastExecTime, LAST_EXEC_PARAM as lastExecParam from regulatory.BTN_FUNC_FLOW_CTRL where BTN_NAME = ? and LAST_EXEC_TIME >= SYSTIMESTAMP - INTERVAL ? MINUTE;
### Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
我想知道为什么会出现这些问题以及如何解决它们。
1条答案
按热度按时间zlhcx6iw1#
Interval literal应该有literals作为其组成部分:它应该是恒定的。
文字
术语“文字”和“常数值”是同义词,指的是固定的数据值。
你试图组合的不是一个常量,因为它有bind variable。
但是,您可以使用间隔算法,并指定间隔的基值,然后将其乘以所需的单位数:
或者使用
numtodsinterval
函数作为变量单位: