ORACLE之PACKAGE-游标变量
刚学pl/sql编程,写了两个package。pkg_temp_fn31和pkg_temp_fn32。内容涉及pl/sql基本语法,游标变量,存储过程(in,out)。
pkg_temp_fn31调用pkg_temp_fn32,pkg_temp_fn32中定义了out游标变量。
- pkg_temp_fn31内有一个procedure test(p_mapid number)
创建包规范
1 create or replace package pkg_temp_fn31 is 2 --25-03-2016 3 procedure test(p_mapid number); 4 end pkg_temp_fn31; 5 --exec pkg_temp_fn31.test(&p_mapid);执行此包
创建包体pkg_temp_fn31
create or replace package body pkg_temp_fn31 is procedure test(p_mapid number) is p_cursor pkg_temp_fn32.ref_cursor;-- p_personno t_fn_person.person_code%type; p_personname t_fn_person.person_name%type; begin pkg_temp_fn32.queryall(p_mapid,p_cursor);-- loop fetch p_cursor into p_personno,p_personname; exit when p_cursor%notfound; dbms_output.put_line(p_personno||'''s person name is '||p_personname); end loop; end test; end pkg_temp_fn31;
- kg_temp_fn32内有一个procedure queryall(pmap_id number ,p_cursor out ref_cursor)
创建包规范
1 create or replace package pkg_temp_fn32 is 2 --25/03/2016 3 type ref_cursor is ref cursor;-- 4 procedure queryall(pmap_id number ,p_cursor out ref_cursor); 5 end pkg_temp_fn32;
创建包体pkg_temp_fn32
create or replace package body pkg_temp_fn32 is procedure queryall(pmap_id number ,p_cursor out ref_cursor) is RF pkg_temp_fn32.ref_cursor; begin open RF for select x.person_code,x.person_name from t_fn_person x where x.map_id=pmap_id; p_cursor:=RF; end queryall; end pkg_temp_fn32;
执行结果:
命令窗口:
一般sql窗口:
-- 调用过程 call pkg_temp_fn31.test('000001')
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨小小打赏一下吧,如果囊中羞涩,不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
![qq群](https://files-cdn.cnblogs.com/files/hoaprox/qqqun.bmp)
![微信](https://files.cnblogs.com/files/hoaprox/zsm.bmp)