![](/img/trans.png)
[英]Issue while facing calling oracle stored procedure from Java using JDBC TEMPLATE
[英]Example for calling a stored procedure in Oracle SQL from Java using JDBC
我已经看到了一些示例,这些示例通过使用CallableStatement
返回类型为数字的过程,然后设置IN
参数并根据返回类型注册OUT
参数。
但是,如果OUT
参数是SELECT
语句返回的表,该如何做呢?
我试图找到一些例子,但没有用。 请帮忙。
这是一些示例代码,其中OUT
参数是整数
// Prepare to call the stored procedure RAISESAL.
// This sample uses the SQL92 syntax
CallableStatement cstmt = conn.prepareCall ("{? = call RAISESAL (?, ?)}");
// Declare that the first ? is a return value of type Int
cstmt.registerOutParameter (1, Types.INTEGER);
// We want to raise LESLIE's salary by 20,000
cstmt.setString (2, "LESLIE"); // The name argument is the second ?
cstmt.setInt (3, 20000); // The raise argument is the third ?
// Do the raise
cstmt.execute ();
// Get the new salary back
int new_salary = cstmt.getInt (1);
System.out.println ("The new salary is: " + new_salary);
但是我想要一个示例,其中OUT
参数是一个表( SYS_REFCURSOR
)。
您需要将第一个参数声明为REF_CURSOR
cstmt.registerOutParameter (1, oracle.jdbc.OracleTypes.CURSOR);
这是一个使用JDBC-OCI的完整示例,但您可以使用JDBC-thin(实际上应该使用): https : //docs.oracle.com/cd/A97335_02/apps.102/a83724/samapp5.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.