今天遇见一个存储过程的试题:
有表emp 字段id,sal(工资)
工资大于2000,工资加100,工资大于1000 ,工资加200,其他工资加250;

解决方案 »

  1.   

    create or replace procedure add_sal
    as
    begin
          update emp set
          sal=sal+(case when sal>2000 then 100
                        when sal>1000 and sal<=2000 then 200
                        else 250 end )
          ;
          commit;
    end;
      

  2.   

    你这个直接查询即可,不需要存储过程。select id,
      case when sal > 2000 then sal + 100
           when sal > 1000 and sal <= 2000 then sal + 200
           else sal + 250
      end
    from emp
      

  3.   

    如果是更新则:
    update emp 
    set sal = 

      case when sal > 2000 then sal + 100
           when sal > 1000 and sal <= 2000 then sal + 200
           else sal + 250
      end
    )
      

  4.   


    ------sinpoal
    create or replace procedure upd_sal_emp
    is
    begin 
    update emp set sal=sal+(case when sal>2000 then 100 
                             when sal >1000 and sal<2000 then 200 else 250 end)
    end upd_sal_emp
                          
    exec upd_sal_emp ---可直接用查询语句
    select id ,sal+(case when sal>2000 then 100 
                             when sal >1000 and sal<2000 then 200 else 250 end) sal
                             from emp
      

  5.   

    --可以直接来就可以,update emp1 set sal=(case when sal>=2000 then sal+100
    when sal>=1000 and sal<2000 then sal+200
    else sal+250 end)
      

  6.   


    create or replace procedure pro1
    as 
    begin
    update emp set sale=sale+(case when sale>2000 then 100
                                 when sale>1000 and sale<=2000 then 200 else 250
    end)
    end