PL/SQL Cursor Properties and Limits on the Number of Cursors

a cursor attribute

%found: the cursor found the record is true
%notfound: true if the cursor did not find the record
%isopen: determine whether the cursor is open
%rowcount: The number of rows affected
 
Two examples
Demonstrate the %isopen property
1. Code
  1. set serveroutput on
  2. declare
  3. --定义光标
  4. cursor cemp isselect empno,empjob from emp;
  5. pempno emp.empno%type;
  6. pjob emp.empjob%type;
  7. begin
  8. open cemp;
  9. if cemp%isopen then
  10. dbms_output.put_line('光标已经打开');
  11. else
  12. dbms_output.put_line('光标没有打开');
  13. endif;
  14. close cemp;
  15. end;
  16. /
2. Running results
Cursor is already open
 
PL/SQL procedure completed successfully.
 
Demonstration of the %rowcount property
1. Code
  1. set serveroutput on
  2. declare
  3. --定义光标
  4. cursor cemp isselect empno,empjob from emp;
  5. pempno emp.empno%type;
  6. pjob emp.empjob%type;
  7. begin
  8. open cemp;
  9. loop
  10. --取出一条记录
  11. fetch cemp into pempno,pjob;
  12. exitwhen cemp%notfound;
  13. --打印rowcount的值
  14. DBMS_OUTPUT.PUT_LINE('rowcount:'||cemp%rowcount);
  15. end loop;
  16. close cemp;
  17. end;
  18. /
2. Running results
rowcount:1
rowcount:2
rowcount:3
rowcount:4
rowcount:5
rowcount:6
rowcount:7
rowcount:8
rowcount:9
rowcount:10
rowcount:11
rowcount:12
rowcount:13
rowcount:14
 
Three-cursor limit
1. Concept
By default, the oracle database only allows 300 cursors to be opened in the same session
Cursor limit viewing method:
  1. SQL> show parameter cursor
  2. NAME TYPE VALUE
  3. -----------------------------------------------------------------------------
  4. cursor_sharing string EXACT
  5. cursor_space_for_time boolean FALSE
  6. open_cursors integer 300
  7. session_cached_cursors integer 50
Modify the limit on the number of cursors:
alter system set open_cursors = 400 scope=both;
the value of scope
both: Change the current instance and also change the parameter file.
memory: Only the current instance is changed, not the parameter file.
spfile: Only the parameter file is changed, but the current instance is not changed. The database needs to be restarted.
2. Examples
  1. SQL> alter system set open_cursors =400 scope=both;
  2. 系统已更改。
  3. SQL> show parameter cursor
  4. NAME TYPE VALUE
  5. -----------------------------------------------------------------------------
  6. cursor_sharing string EXACT
  7. cursor_space_for_time boolean FALSE
  8. open_cursors integer 400
  9. session_cached_cursors integer 50

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326126210&siteId=291194637
Recommended