简体   繁体   English

在Oracle PL / SQL中调用存储过程

[英]Calling Stored Procedure in Oracle PL/SQL

I have written a procedure with a cursor in it in Oracle 11g so that I can use it in Java code. 我在Oracle 11g中编写了一个带有游标的过程,以便我可以在Java代码中使用它。 Can anybody tell me how I can use this procedure and call it from Java code? 任何人都可以告诉我如何使用此过程并从Java代码中调用它?

create or replace
PROCEDURE show_students
(
students_cursor OUT SYS_REFCURSOR
)AS
BEGIN
OPEN students_cursor FOR
SELECT * from students;
END show_students;

use this: 用这个:

CallableStatement stmt = connection.prepareCall("BEGIN SHOW_STUDENTS(?); END;");
stmt.registerOutParameter(1, OracleTypes.CURSOR); //REF CURSOR
stmt.execute();
rs = ((OracleCallableStatement)stmt).getCursor(1);

I suggest using function in this case instead of procedure. 我建议在这种情况下使用函数而不是程序。

Notice that I suppose you have the connection to DB as "connection" 请注意,我认为您将数据库连接为“连接”

Source: How do I return a sys_refcursor from oracle SP in java? 来源: 如何从java中的oracle SP返回sys_refcursor?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM