Oracle Procedure (PL/SQL) 实践归纳(3)之在Java利用Procedure获取结果集

来源:互联网 发布:pc28大神软件下载 编辑:程序博客网 时间:2024/05/11 05:54

首先是PL/SQL中procedure参数如何声明的问题,最主要是输出参数怎么定义。找了一些资料得知,可以一个输出参数表示cursor,然后在Java中获取这个cursor),而这个输出参数的类型为:sys_refcursor . 这是专门针对cursor的类型,出现在Oracle9i以后。比如:

create or replace procedure searchEmployee(i_no in numbero_cursor out sys_refcursor)

procedure主体中,只需要执行下句就可以完成赋值查询:

open o_cursor for select-statement

 

open o_cursor for
    select * from employee where em_name = i_name;

注意open-for这样的结构

 

完成在数据库的procedure写入之后,就可以开始写Java程序,关键点有:

1.registerOutParameter(int, OracleTypes.CURSOR);

2.ResultSet rs = (ResultSet) CallableStatement.getObject(int);

其余就跟一般的一样了。

 

参考:http://www.javaworld.com.tw/jute/post/view?bid=21&id=148969&sty=1&tpg=1&age=-1

例如:
原创粉丝点击