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>