oracle10g_plsql_rercursor_type_table of_小引例_bulk collect into

wisdomone1發表於2010-08-06

SQL> set serveroutput on
SQL> r
  1  declare
  2  type mytable is table of dept%rowtype;--此型別定義用到table of且rowtype,為表的部分記錄集,而非某特定的行
  3  l_mydata mytable;
  4  l_refc sys_refcursor; --定義一個refcursor
  5  begin
  6  open l_refc for select deptno,dname,loc from dept;--開啟以上定義的refcursor
  7  fetch l_refc bulk collect into l_mydata;--利用fetch選項bulk collect into把refcursor結果集提取到或傳遞到l_mydata變數(型別為以上定義的table of rowtype)
  8  close l_refc;--提取refcursor遊標完事,關閉它吧,別佔用資源
  9  for i in 1..l_mydata.count loop --這裡用了for,count,loop(注:加了個count)
 10  dbms_output.put_line(l_mydata(i).deptno||' '||l_mydata --顯示每個具體的值用 (i)

(i).dname||' '||l_mydata(i).loc);
 11  end loop;
 12* end;
10 ACCOUNTING NEW YORK  ##把表dept記錄全顯示出來了
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

PL/SQL procedure successfully completed.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-670464/,如需轉載,請註明出處,否則將追究法律責任。

相關文章