我正在尝试使用 JdbcTemplate 从 oracle 匿名块读取值
我正在尝试使用 JdbcTemplate 从 Oracle 匿名块读取值。这是我的 java 代码:
getJdbcTemplate().queryForObject(sql, Boolean.class);
这是 sql:
DECLARE
CRS SYS_REFCURSOR;
BEGIN
OPEN CRS FOR SELECT CASE
WHEN
1 > 0
THEN 1
ELSE 0
END
FROM DUAL;
END;
我收到此错误:
SQL state [99999]; error code [17166]; Cannot perform fetch on a PLSQL statement: next; nested exception is java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next
I am trying to read a value from oracle anonymous block using JdbcTemplate. Here is my java code:
getJdbcTemplate().queryForObject(sql, Boolean.class);
And here is the sql:
DECLARE
CRS SYS_REFCURSOR;
BEGIN
OPEN CRS FOR SELECT CASE
WHEN
1 > 0
THEN 1
ELSE 0
END
FROM DUAL;
END;
I am receiving this error:
SQL state [99999]; error code [17166]; Cannot perform fetch on a PLSQL statement: next; nested exception is java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
公共T queryForObject(String sql, ClassrequiredType) throws DataAccessException
接受一个 SQL 查询,该查询将生成包含单行的结果集,并使用返回结果集中的该行构造所需类型的对象。代码:
打开一个包含单行结果集的游标;但是,游标作为 PL/SQL 匿名块中的局部变量保存,并且永远不会“返回”到调用 PL/SQL 的应用程序代码。
传统的方法是在没有 PL/SQL 包装器的情况下使用 SQL:
您可以尝试使用 PL/SQL 块中的 DBMS_SQL.RETURN_RESULT ,但这仅在 Oracle 12 中可用,并且没有相同的功能传统 SQL 查询的支持级别,因此它可能不起作用:
public <T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException
takes an SQL query that will generate a result set with a single row and constructs an object of the required type using that row from the returned result set.The code:
Opens a cursor that would contain a result set with a single row; however, the cursor is held as a local variable within the PL/SQL anonymous block and is never "returned" to the application code that calls the PL/SQL.
The traditional way would be to use SQL without the PL/SQL wrapper:
You could try using
DBMS_SQL.RETURN_RESULT
from the PL/SQL block but that is only available from Oracle 12 and it does not have the same level of support that traditional SQL queries do so it may not work: