mybatis分页查询时ORA-00907: 缺失右括号

J2EE 码拜 9年前 (2015-04-18) 2623次浏览 0个评论

mybatis语句:

SELECT  *  FROM
            (SELECT 
				id as id,
				appserialnumber as appserialnumber,
				who as who,
				createtime as createtime,
				operatedtype as operatedtype,
				operate as operate,
				operatedobject as operatedobject,
				description as description,
				result as result,
				ROWNUM AS row_num
			 FROM server_log ROWNUM < (#{startRecord}+#{total})) t_temp
		       WHERE t_temp.row_num >= #{startRecord}

然后控制台打印语句:
10:06:51,114 DEBUG Connection:27 – ooo Connection Opened
10:06:51,442 DEBUG PreparedStatement:27 – ==>  Executing: select count(*) from server_log 
10:06:51,442 DEBUG PreparedStatement:27 – ==>  Executing: select count(*) from server_log 
10:06:51,442 DEBUG PreparedStatement:27 – ==> Parameters: 
10:06:51,442 DEBUG PreparedStatement:27 – ==> Parameters: 
10:06:51,630 DEBUG Connection:27 – ooo Connection Opened
10:06:51,646 DEBUG PreparedStatement:27 – ==>  Executing: SELECT * FROM (SELECT id as id, appserialnumber as appserialnumber, who as who, createtime as createtime, operatedtype as operatedtype, operate as operate, operatedobject as operatedobject, description as description, result as result, ROWNUM AS row_num FROM server_log ROWNUM < (?+?)) t_temp WHERE t_temp.row_num >= ? 
10:06:51,646 DEBUG PreparedStatement:27 – ==>  Executing: SELECT * FROM (SELECT id as id, appserialnumber as appserialnumber, who as who, createtime as createtime, operatedtype as operatedtype, operate as operate, operatedobject as operatedobject, description as description, result as result, ROWNUM AS row_num FROM server_log ROWNUM < (?+?)) t_temp WHERE t_temp.row_num >= ? 
10:06:51,646 DEBUG PreparedStatement:27 – ==> Parameters: 0(Integer), 10(Integer), 0(Integer)
10:06:51,646 DEBUG PreparedStatement:27 – ==> Parameters: 0(Integer), 10(Integer), 0(Integer)
2014-8-1 10:06:51 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet SearchServlet threw exception
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: ORA-00907: 缺失右括号

### The error may involve com.itrus.mylog.domain.ServerLog.selectAllServerLog-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLException: ORA-00907: 缺失右括号

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:77)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
at com.itrus.mylog.dao.impl.SearchDAOImpl.searchPagination(SearchDAOImpl.java:37)
at com.itrus.mylog.service.impl.SearchServiceImpl.searchPagination(SearchServiceImpl.java:24)
at com.itrus.mylog.servlet.SearchServlet.search(SearchServlet.java:53)
at com.itrus.mylog.servlet.SearchServlet.service(SearchServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: ORA-00907: 缺失右括号

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:796)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1031)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:836)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1116)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:45)
at $Proxy1.execute(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:39)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:55)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:41)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:216)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:95)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:72)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:75)
… 18 more

求指点,是语句哪里写错了么?

mybatis分页查询时ORA-00907: 缺失右括号
 (SELECT 
                id as id,
                appserialnumber as appserialnumber,
                who as who,
                createtime as createtime,
                operatedtype as operatedtype,
                operate as operate,
                operatedobject as operatedobject,
                description as description,
                result as result,
                ROWNUM AS row_num
             FROM server_log  and ROWNUM &lt; (#{startRecord}+#{total}))
mybatis分页查询时ORA-00907: 缺失右括号
2分
不知道是不是(#{startRecord}+#{total}) 这里引起的
你试试sum(#{startRecord},#{total})测试下
或者把这句干掉试试
最好的是这个加法算法不要在xml里面做 , 后台加好再传进来
mybatis分页查询时ORA-00907: 缺失右括号
5分
FROM server_log  ROWNUM &lt; (#{startRecord}+#{total})
这句是不是有问题? 少where?
mybatis分页查询时ORA-00907: 缺失右括号
6分
 (SELECT 
                id as id,
                appserialnumber as appserialnumber,
                who as who,
                createtime as createtime,
                operatedtype as operatedtype,
                operate as operate,
                operatedobject as operatedobject,
                description as description,
                result as result,
                ROWNUM AS row_num
             FROM server_log  where ROWNUM &lt; (#{startRecord}+#{total}))

mybatis分页查询时ORA-00907: 缺失右括号
2分
你的select子查询少个右括号,不是错误很明显吗。
mybatis分页查询时ORA-00907: 缺失右括号
5分
1L and 改成where就行了
mybatis分页查询时ORA-00907: 缺失右括号
引用 1 楼 u012463264 的回复:

 (SELECT 
                id as id,
                appserialnumber as appserialnumber,
                who as who,
                createtime as createtime,
                operatedtype as operatedtype,
                operate as operate,
                operatedobject as operatedobject,
                description as description,
                result as result,
                ROWNUM AS row_num
             FROM server_log  and ROWNUM &lt; (#{startRecord}+#{total}))

照着你说的改了,但是还是报缺失右括号!
控制台输出:

10:26:42,536 DEBUG Connection:27 – ooo Connection Opened
10:26:42,853 DEBUG PreparedStatement:27 – ==>  Executing: select count(*) from server_log 
10:26:42,853 DEBUG PreparedStatement:27 – ==>  Executing: select count(*) from server_log 
10:26:42,854 DEBUG PreparedStatement:27 – ==> Parameters: 
10:26:42,854 DEBUG PreparedStatement:27 – ==> Parameters: 
10:26:43,050 DEBUG Connection:27 – ooo Connection Opened
10:26:43,060 DEBUG PreparedStatement:27 – ==>  Executing: SELECT * FROM (SELECT id as id, appserialnumber as appserialnumber, who as who, createtime as createtime, operatedtype as operatedtype, operate as operate, operatedobject as operatedobject, description as description, result as result, ROWNUM AS row_num FROM server_log and ROWNUM < (?+?)) t_temp WHERE t_temp.row_num >= ? 
10:26:43,060 DEBUG PreparedStatement:27 – ==>  Executing: SELECT * FROM (SELECT id as id, appserialnumber as appserialnumber, who as who, createtime as createtime, operatedtype as operatedtype, operate as operate, operatedobject as operatedobject, description as description, result as result, ROWNUM AS row_num FROM server_log and ROWNUM < (?+?)) t_temp WHERE t_temp.row_num >= ? 
10:26:43,061 DEBUG PreparedStatement:27 – ==> Parameters: 0(Integer), 10(Integer), 0(Integer)
10:26:43,061 DEBUG PreparedStatement:27 – ==> Parameters: 0(Integer), 10(Integer), 0(Integer)
2014-8-1 10:26:43 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet SearchServlet threw exception
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: ORA-00907: 缺失右括号

mybatis分页查询时ORA-00907: 缺失右括号
引用 6 楼 cbxjj 的回复:

1L and 改成where就行了

正解!恩,就是这样,改为where就正确了!谢谢!

mybatis分页查询时ORA-00907: 缺失右括号
引用 4 楼 u012463264 的回复:

 (SELECT 
                id as id,
                appserialnumber as appserialnumber,
                who as who,
                createtime as createtime,
                operatedtype as operatedtype,
                operate as operate,
                operatedobject as operatedobject,
                description as description,
                result as result,
                ROWNUM AS row_num
             FROM server_log  where ROWNUM &lt; (#{startRecord}+#{total}))

恩,原来你在下面又重新回复了一次,添加where就对了!谢谢!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明mybatis分页查询时ORA-00907: 缺失右括号
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!