当处理多重条件分支时,不仅可以使用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

相关文章:

  • 2021-11-21
  • 2022-12-23
  • 2022-01-21
  • 2021-08-16
  • 2021-06-01
  • 2021-10-28
  • 2021-10-10
  • 2022-12-23
猜你喜欢
  • 2021-09-06
  • 2021-08-13
  • 2021-12-09
  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案