【问题标题】:Using of cursors as function output in procedure (Oracle)在过程中使用游标作为函数输出 (Oracle)
【发布时间】:2011-11-29 12:00:55
【问题描述】:

我正在努力寻找解决方案,但总是有问题。那么我的问题是什么:

我有一个函数:

function fun1 (
p_param1 number) return sys_refcursor
is 
  c_result sys_refcursor;
begin
  open c_result for select e.username, c.contract_id from employees e 
    join contracts c on c.employee_id = e.employee_id;
  return c_result;
end fun1;

我想在我的存储过程中使用这个函数:

procedure proc1 (...) 
is ...
cur_contract sys_refcursor;
begin
...
  open cur_contract for fun1(p_param1);
  loop
    fetch cur_contract into v_username, v_contract_id;
    exit when cur_contract%notfound;
    ...
  end loop;
  close cur_contract;
...
end proc1;

我收到错误:“open cur_contract for fun1(p_param1);”行中的表达式类型错误

我应该改变什么来使我的程序正常工作?

【问题讨论】:

    标签: oracle cursor sys-refcursor


    【解决方案1】:

    你已经在 fun1 中打开了光标。请尝试以下操作:

    procedure proc1 (...)
      is
      ...
      cur_contract sys_refcursor;
    begin
      ...
     cur_contract := fun1(p_param1);
    
     loop
       fetch cur_contract into v_username, v_contract_id;
       exit when cur_contract%notfound;
       ...
     end loop;
    
     close cur_contract;
     ...
    end proc1; 
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2018-01-02
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      相关资源
      最近更新 更多