使用case-when实现if-then-else逻辑

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--类似创建表
create table empcp as select * from emp where 1=1;
--1=2无数据

<!-- more -->

declare
v_emp empcp%rowtype;
begin
select * into v_emp from empcp where ename='&雇员名';
case v_emp.job
when 'CLERK' then
update empcp set sal=sal+500 where empno=v_emp.empno;
when 'SALESMAN' then
update empcp set sal=sal+1000 where empno=v_emp.empno;
when 'ANALYST' then
update empcp set sal=sal+1500 where empno=v_emp.empno;
else
update empcp set sal=sal+2000 where empno=v_emp.empno;
end case;
commit;
end;
/
文章目录
|