使用控制结构——条件分支语句——CASE语句

当处理多重条件分支时,不仅可以使用if语句,而且可以使用CASE语句。因为使用CASE语句更加简洁,而且执行效率也更好,所以建议使用CASE 语句。


注意: 为了避免CASE_NOT_FOUND 例外,在编写CASE语句时应该带有ELSE 子句。


declare 
v_deptno emp.deptno%type;
begin
v_deptno:=&no;
case v_deptno
when 10 then
update emp set comm=100 where deptno=v_deptno;
when 20 then
update emp set comm=80 where deptno=v_deptno;
when 30 then 
update emp set comm=50 where deptno=v_deptno;
else
dbms_output.put_line('不存在该部门: ');
end case;
end;
/

输入no的值:10

-------------------------------------------

作者:赵杰迪

-------------------------------------------

原文地址:https://www.cnblogs.com/zhaojiedi1992/p/oracle11g_sql_005.html