pl/sql編程(七) 判斷

–編寫一個過程,可以輸入一個僱員名如果該員工的工資低於2000 就給該員工工資增加20%
否則增加10%

create or replace procedure sp1(spName varchar2) is
v_sal emp.sal%type;
begin
select sal into v_sal from emp where  name=spName;
if v_sal<2000 then
update emp set sal=sal+sal*0.2 where name=spName;
else
update emp set sal=sal*1.1 where name=spName;
end if;
end;
/

–編寫一個過程,輸入員工ID 如果部門是1 則工資增加300元,2號部門增加400,其他部門
否則增加100

create or replace procedure sp1(spNo number) is
v_deptno emp.deptno%type;
begin
select deptno into v_deptno from emp where  id=spNo;
if v_deptno=1 then
update emp set sal=sal+300 where   id=spNo;
elsif v_deptno=2 then
update  emp set sal=sal+400 where  id=spNo;
else
update emp set sal=sal+100 where  id=spNo;
end if;
end;
/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章