Oracle if else 、case when 判断示例

declare 
  -- 声明奖金的变量
  v_comm emp.comm%type;
begin
-- 查询出员工的奖金
   select comm into v_comm from emp where empno=&no;
-- 判断如果员工没有奖金,把基本工资的10%作为奖金
   if v_comm is null then
      update emp set comm=sal*0.1 where empno=&no;
--如果原先奖金低于1000,提升到1000
   elsif v_comm<1000 then
       update emp set comm=1000 where empno=&no;
-- 其他情况  把奖金提升10%
   else
       update emp set comm=comm*1.1 where empno=&no;
   end if;  
end;
declare
-- 声明部门编号的变量
  v_deptno emp.deptno%type:=&no;

begin
  case v_deptno
     when 10 then
       dbms_output.put_line('技术部');
     when 20 then
       dbms_output.put_line('业务部');
     when 30 then
       dbms_output.put_line('开发部');
     when 40 then
       dbms_output.put_line('财务部');
     else
       dbms_output.put_line('您查找的部门不存在');
  end case;

end;

猜你喜欢

转载自www.cnblogs.com/zhangmenghui/p/10828924.html