Oracle中用游标更新字段值的面试题

Linux大全评论306 views阅读模式

如下表

  1. SQL> set pagesize 60;  
  2. SQL> run;  
  3.   1* select * from employee  
  4.   
  5. NAME           SALARY  
  6. ---------- ----------  
  7. SMITH             800  
  8. ALLEN            1600  
  9. WARD             1250  
  10. JONES            2975  
  11. MARTIN           1250  
  12. BLAKE            2850  
  13. CLARK            2450  
  14. SCOTT            3000  
  15. KING             5000  
  16. TURNER           1500  
  17. ADAMS            1100  
  18. JAMES             950  
  19. FORD             3000  
  20. MILLER           1300  
  21.   
  22. 已选择14行。  
SQL>  create or replace procedure emp_test
  is
   v_name employee.name%type;
   v_sal employee.salary%type;
   cursor cursor_sal is
   select name,salary from employee where salary<2500;
   begin
   open cursor_sal ;
   loop
   fetch cursor_sal into v_name,v_sal;
   exit when cursor_sal%notfound;
   update employee set salary=salary*1.2 where name=v_name;
   end loop;
   close cursor_sal;
   end;
   /

过程已创建。
  1. SQL> set serveroutput on ;  
  2. SQL> exec emp_test;  
  3.   
  4. PL/SQL 过程已成功完成。  
  5.   
  6. SQL> select * from employee;  
  7.   
  8. NAME           SALARY  
  9. ---------- ----------   
  10. SMITH          1382.4  
  11. ALLEN            1920  
  12. WARD             1500  
  13. JONES            2975  
  14. MARTIN           1500  
  15. BLAKE            2850  
  16. CLARK            2940  
  17. SCOTT            3000  
  18. KING             5000  
  19. TURNER           1800  
  20. ADAMS            1320  
  21. JAMES            1368  
  22. FORD             3000  
  23. MILLER           1560  
  24.   
  25. 已选择14行。  

企鹅博客
  • 本文由 发表于 2019年9月20日 16:45:49
  • 转载请务必保留本文链接:https://www.qieseo.com/185361.html

发表评论