Understanding of Oracle SQL cursor

Source: Internet
Author: User

The "SQL" Mark written in the implicit cursor. For example, SQL % ROWCOUNT indicates that the implicit cursor has several rows of records. The explicit cursor is customized by the developer, you can also use C1 % ROWCOUNT to indicate the number of rows in the cursor C1. Usually, explicit cursors are opened in OPEN mode.

Use an explicitly defined cursor to OPEN it in OPEN mode. The usage is as follows:

  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 ('current row of cursor 1: '| c1 % rowcount );
  10. Loop
  11. Fetch c1 into v_rownum, v_tablename;
  12. Exit when c1 % notfound;
  13. Dbms_output.put_line ('cursor current row: '| c1 % rowcount | 'table_name:' | v_tablename );
  14. End loop;
  15. Dbms_output.put_line ('current row of cursor 2: '| c1 % rowcount );
  16. Close c1;
  17. End;

Run the command in SQLPUS to obtain the following result.

  1. Current number of cursor rows: 0-1
  2. Cursor current row: 1 table_name: T_SS
  3. Cursor current row: 2 table_name: T_TARGET
  4. Cursor current row: 3 table_name: T_SS_NORMAL
  5. Cursor current row: 4 table_name: T_MYSTAT
  6. Cursor current row: 5 table_name: T_WXL_GETDATA_LOG
  7. Cursor current row: 6 table_name: ALL_OBJ
  8. Cursor current row: 7 table_name: DBA_OBJ
  9. Cursor current row: 8 table_name: T_RPT_XXX
  10. Cursor current row: 9 table_name: CMS_DOC_BODY
  11. Cursor current row
  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.