Oracle cursor (1) Explicit cursor

Source: Internet
Author: User
Tags oracle cursor


Oracle cursor (1) Explicit cursor usage steps 1. Declare a cursor

2. Open the cursor syntax www.2cto.com

 

3. Extract the cursor syntax

 

4. Close the cursor syntax
Complete show cursor example
Cursor attributes
Syntax
Overall example: Add a salary for an employee: [SQL] <strong> <span style = "font-size: 18px;"> declare hire_date date; -- store the employee's entry date e_id number; -- store employee id cursor emp_cur is -- Define the cursor select id, hire_date from employees; begin www.2cto.com open emp_cur; -- open the cursor loop fetch emp_cur into e_id, hire_date; -- save data to the variable one by one, and move the cursor backward to exit when emp_cur % notfound; if 100 * (2010-to_char (hire_date, 'yyyy ')) <1000 then update salary set salarvalue = salaryvalue + 100 * (2010-to_char (hire_date, 'yyyy') where emplyeeid = e_id; else update salary set salarvalue = salaryvalue + 1000 where emplyeeid = e_id; end if; close emp_cur; end loop; </span> </strong> the display cursor is often used together with the loop, the simplified Traversal method is as follows:

Example: www.2cto.com [SQL] <strong> <span style = "font-size: 18px;"> declare type emplyee_record is record (name varchar2 (50), department_name varchar2 (20 )); cursor emp_cur is select name, department_name from emplyees s, orders ments d where e. department_id = d. department_id; begin for employee_record in emp_cur loop dbms_output.put_line (employee_record.name | '| begin); end loop; end; </span> </strong>

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.