如何在包中的过程之间传递游标行类型

时间:2017-12-19 11:56:48

标签: oracle plsql

我在包中有一个显式游标,我根据这个游标创建了rowtype,如何在程序之间传递这个rowtype? 编译时我的例子挂断了。

cursor cur(param) is 
select * from dual where param = 1;
rec cur%rowtype;

procedure do_something_with_rec(p_rec in cur%rowtype)
is
begin
  dbms_output.put_line(p_rec.dummy);
end;

procedure main(param)
is
begin
 open cur(param);
 loop
   fetch into rec;
   exit when cur%notfound;
 end loop;
 close cur;

 do_something_with_rec(rec);
end;

1 个答案:

答案 0 :(得分:2)

您忘记在游标中添加参数类型,过程main的定义以及fetch添加游标名称。这个包编译和工作:

-- package

create or replace package p_test is

  procedure main(param in number);

end p_test;

-- body

create or replace package body p_test is

  cursor cur(param in number) is select * from dual where param = 1;
  rec cur%rowtype;

procedure do_something_with_rec(p_rec in cur%rowtype) is
begin
  dbms_output.put_line(p_rec.dummy);
end;

procedure main(param in number) is
begin
  open cur(param);
  loop
    fetch cur into rec;
    exit when cur%notfound;
  end loop;
  close cur;

  do_something_with_rec(rec);
end;
end p_test;