刚学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)

  创建包规范

 create or replace package pkg_temp_fn31 is
   --25-03-2016
   procedure test(p_mapid number);
 end pkg_temp_fn31;
 --exec pkg_temp_fn31(&p_mapid);执行此包

  创建包规范

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_fn2内有一个procedure queryall(pmap_id number ,p_cursor out ref_cursor)

  创建包规范  

 create or replace package pkg_temp_fn32 is
 --25/03/2016
   type ref_cursor is ref cursor;--
   procedure queryall(pmap_id number ,p_cursor out ref_cursor);
 end 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;

执行结果:

ORACLE之PACKAGE-游标变量-LMLPHP

05-06 01:53