重用(重新打开)Oracle refcursor

时间:2012-02-27 00:24:28

标签: oracle sys-refcursor

我有两个Oracle refcursors,一个包含Rows(CustomersList)列表,另一个包含每个Row的列名(PriceGroups)。 我需要遍历每个Row和列并更新每个Row / Column的交集。 如何重新定位列光标以反复开始第一列。 该表如下所示

Customer   | pricegroupA | priceGroupB | priceGroupC | priceGroupEtc|
-----------+---------------------------------------------------------
aaaa       | 23.5        | 23.8        | 30.9        | 41.3         |
---------------------------------------------------------------------
bbbb       | 21.7        | 24.6        | 49.9        | 45.9         |
---------------------------------------------------------------------
....

1 个答案:

答案 0 :(得分:2)

如果您分享了一堆代码我可以为您重写,但我认为以下示例对您有所帮助。

declare
  type r_cursor is REF CURSOR;
  c_emp r_cursor;
  en emp.ename%type;
begin
   /*Opening the refCursor for the first time*/
   open c_emp for select ename from emp;
  loop
      fetch c_emp into en;
      exit when c_emp%notfound;
      dbms_output.put_line(en);
  end loop;
  /*Closing it*/  
  close c_emp;
 /*Opening the refCursor again after it is closed*/
  open c_emp for select ename from emp;
  loop
      fetch c_emp into en;
      exit when c_emp%notfound;
      dbms_output.put_line(en);
  end loop;
  close c_emp;
  /*Closing it again*/  
end;