Oracle SQL的cursor理解

來源:互聯網
上載者:User

隱式遊標中大寫的"SQL"標識,如SQL%ROWCOUNT表示隱式遊標有幾行記錄;顯式遊標由開發人員自訂,也可以使用如C1%ROWCOUNT表示遊標C1有幾行記錄。通常顯式遊標都是使用OPEN方式開啟的。

使用顯式定義的遊標使用OPEN方式開啟,它的使用方法如下例所示:

  1. set serveroutput on
  2. declare
  3. cursor c1 is
  4. select rownum ,table_name from user_tables where rownum < 10 ;
  5. v_rownum number ;
  6. v_tablename varchar2 ( 256 );
  7. begin
  8. open c1;
  9. dbms_output.put_line( ' 遊標當前行數 1:' || c1% rowcount );
  10. loop
  11. fetch c1 into v_rownum,v_tablename;
  12. exit when c1% notfound ;
  13. dbms_output.put_line( ' 遊標當前行 :' || c1% rowcount || ' table_name:' ||v_tablename);
  14. end loop ;
  15. dbms_output.put_line( ' 遊標當前行數 2:' || c1% rowcount );
  16. close c1;
  17. end ;

在SQLPUS中執行,得到如下結果。

  1. 遊標當前行數 1:0
  2. 遊標當前行 :1 table_name:T_SS
  3. 遊標當前行 :2 table_name:T_TARGET
  4. 遊標當前行 :3 table_name:T_SS_NORMAL
  5. 遊標當前行 :4 table_name:T_MYSTAT
  6. 遊標當前行 :5 table_name:T_WXL_GETDATA_LOG
  7. 遊標當前行 :6 table_name:ALL_OBJ
  8. 遊標當前行 :7 table_name:DBA_OBJ
  9. 遊標當前行 :8 table_name:T_RPT_XXX
  10. 遊標當前行 :9 table_name:CMS_DOC_BODY
  11. 遊標當前行數 2:9
  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.