Use of SQL cursors-cursor FOR loop small example _mssql

Source: Internet
Author: User

Example: Displays all employee names and their salaries for the EMP table:

Copy Code code as follows:

Declare
Cursor Emp_cursor is select ename,sal from EMP;
Begin
For Emp_record in Emp_cursor loop
Dbms_output.put_line (' Name: ' | | emp_record.ename| | ', wages: ' | | Emp_record.sal);
End Loop;
End;
/

Anonymous block completed
Name: SMITH, Salary: 880
Name: ALLEN, Salary: 1600
Name: WARD, Salary: 1250
Name: JONES, Salary: 3272.5
Name: MARTIN, Salary: 1250
Name: BLAKE, Salary: 2850
Name: CLARK, Salary: 2450
Name: SCOTT, Salary: 2000
Name: KING, Salary: 5000
Name: TURNER, Salary: 1500
Name: ADAMS, Salary: 1210
Name: JAMES, Salary: 950
Name: FORD, Salary: 3300
Name: MILLER, Salary: 2100

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.