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

问题描述 投票:1回答:1

我在包中有一个显式游标,我根据这个游标创建了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;
oracle plsql
1个回答
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;
© www.soinside.com 2019 - 2024. All rights reserved.