您的位置:首页 > 其它

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

2013-04-30 22:12 323 查看
当处理多重条件分支时,不仅可以使用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐