Ref cursor (Dynamic Cursor)

Source: Internet
Author: User

 

Reference variable--Variable used to store the value pointer

 

 Cursor variable(Ref cursor)

 

  When using a cursor, you do not need to specify the corresponding SELECT statement when defining the cursor.

 

 When the cursor is open (when the cursor is open), you need to specify the SELECT statement, so that a cursor is combined with a select statement.

 

Cursor instance:

 

1.Use pl/SQLYou can enter a department number and display the names and salaries of all employees in the department.

 

2.On the basis of 1, if an employee's salary is less than 200 yuan, an additional 100 yuan will be added.

 

Declare

 

--Define the cursor type

 

TypeSp_emp_copy_cursor Is Ref Cursor;

 

--Define a cursor variable

 

Test_cursor sp_emp_copy_cursor;

 

V_ename emp_copy.ename%Type;

 

V_sal emp_copy.sal%Type;

 

Begin

 

  --Combine test_cursor with a select statement

 

  OpenTest_cursor For Select Ename, Sal From Emp_copy WhereDeptno= &No;

 

  --Fethch)

 

  Loop

 

 Fetch Test_cursor Into V_ename, V_sal;

 

 --Determine whether test_cursor is null

 

 Exit When Test_cursor%Notfound;

 

Dbms_output.put_line('Name :'| V_ename |'Salary :'| V_sal );

 

  End Loop;

 

  --Close cursor

 

  CloseTest_cursor;

 

End;

 

 


From: http://blog.sina.com.cn/s/blog_62e75cd001015mkr.html

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.