Questions about updating field values with a cursor in Oracle

Source: Internet
Author: User


The following table lists the questions about updating field values with cursors in Oracle: [csharp] SQL> set pagesize 60; SQL> run; 1 * select * from employee www.2cto.com name salary ---------- SMITH 800 ALLEN 1600 WARD 1250 JONES 2975 MARTIN 1250 BLAKE 2850 CLARK 2450 SCOTT 3000 KING 5000 TURNER 1500 ADAMS 1100 JAMES 950 FORD 3000 MILLER 1300 already select 14 rows. In this table, if the SALARY column is smaller than 2500, 20% is added. This is very simple, but we have to think about it as follows: first create a cursor to traverse the data of this table in this condition. [Csharp] SQL> create or replace procedure emp_test 2 is www.2cto.com 3 v_name employee. name % type; 4 v_sal employee. salary % type; 5 cursor cursor_sal is 6 select name, salary from employee where salary <2500; 7 begin 8 open cursor_sal; 9 loop 10 fetch cursor_sal into v_name, v_sal; 11 exit when cursor_sal % notfound; 12 update maid set salary = salary * 1.2 where name = v_name; 13 end loop; 14 close curso R_sal; 15 end; 16/The process has been created. [SQL] SQL> set serveroutput on; SQL> exec emp_test; PL/SQL process completed successfully. SQL> select * from employee; www.2cto.com name salary ---------- SMITH 1382.4 ALLEN 1920 WARD 1500 JONES 2975 MARTIN 1500 BLAKE 2850 CLARK 2940 SCOTT 3000 KING 5000 TURNER 1800 ADAMS 1320 JAMES 1368 FORD 3000 MILLER 1560 has selected 14 rows. Prepared by szstephen Zhou

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.