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')

 

posted @ 2016-03-25 11:40  权杖攻城狮  阅读(1456)  评论(0编辑  收藏  举报