使用游标循环检索所有雇员的姓名、工资和部门号,并给部门30的所有雇员工资增加10%(表emp,列:ename,sal,deptno)

解决方案 »

  1.   

    create or replace procedure test_proc
    as
    cursor test_cur is select * from emp;
    begin
    for v_c in test_cur loop
     if v_c.deptno = '30' then 
    update emp set sal=sal+0.1*sal where ename= v_c.ename; 
     end if;
    end loop;
    commit;
    end test_proc;
    /
      

  2.   

    create or replace procedure test_proc
    as
    cursor test_cur is select * from emp;
    begin
    for v_c in test_cur loop
     if v_c.deptno = '30' then 
    update emp set sal=sal+0.1*sal where ename= v_c.ename; 
     end if;
    end loop;
    commit;
    end test_proc;
    /
      

  3.   

    干嘛非要用游标啊!
    update emp  set sal=sal*1.10 where deptno=30
    这样不可以吗?
      

  4.   

    ORACLE游标感觉比SQL 游标麻烦
      

  5.   

    我是个初学者,为了学习游标,我自己写一个全当练习..
    借此地贴出来 
    create table tbs(id int primary key ,姓名 varchar(10),工资 int,部门 varchar(10));insert into tbs
    select 1,'zhang',1000,'30' from dual union all
    select 2,'zhang1',1000,'30' from dual union all
    select 3,'zhang2',1000,'30' from dual union all
    select 4,'zhang3',1000,'50' from dual union all
    select 5,'zhang4',1000,'60' from dual union all
    select 6,'zhang5',1000,'30' from dual  declare 
    cursor cr is select *from tbs;
    beginfor cr_1 in  cr loop
    if cr_1.部门='30' then 
       update tbs set 工资=工资*1.2 where id=cr_1.id;
     end if;
    end loop;
    end;
      

  6.   


    declare
     cursor c is select * from emp where depno=30 for update;
    begin
     for r in c loop
      update emp set sal=sal*1.1 where current of c;
     end loop;
     commit;
    end;
    /