撰寫存盤程序和觸發器,實作對scott公司員工增加獎金,
10部門增加額為工資的20%,
20部門增加額為工資的15%,
30部門增加額為工資的10%,
對于職位為MANAGER且工資高于2500的員工不增加獎金,
select * from emp;
-- 1.觸發器
create or replace trigger t_up_emp
before update on emp
for each row
begin
if :old.job='MANAGER' and :old.sal > 2500 then
select :old.comm into :new.comm from dual;
end if;
end;
-- 1.1驗證觸發器
update emp set comm=sal+150 where empno='7698';
-- 2.存盤程序(繁瑣的)
--create or replace procedure p_up_sal
--is
-- emp_ emp%rowtype;
-- cursor c1(deptno_ emp.deptno%type) is select * from emp where deptno=deptno_;
--begin
-- open c1(10);-------------10部門
-- loop
-- fetch c1 into emp_;
-- exit when c1%notfound;
-- update emp set comm = nvl(comm,0) + 0.2*emp_.sal where empno=emp_.empno;
-- end loop;
-- close c1;
-- open c1(20);-------------20部門
-- loop
-- fetch c1 into emp_;
-- exit when c1%notfound;
-- update emp set comm = nvl(comm,0) + 0.15*emp_.sal where empno=emp_.empno;
-- end loop;
-- close c1;
-- open c1(30);-------------30部門
-- loop
-- fetch c1 into emp_;
-- exit when c1%notfound;
-- update emp set comm = nvl(comm,0) + 0.1*emp_.sal where empno=emp_.empno;
-- end loop;
-- close c1;
-- commit;
--end;
-- 2.存盤程序(清涼的)
create or replace procedure p_up_sal
begin
update emp set comm = nvl(comm,0) + 0.2*sal where empno=10;
update emp set comm = nvl(comm,0) + 0.15*sal where empno=20;
update emp set comm = nvl(comm,0) + 0.1*sal where deptno=30;
commit;
end;
-- 2.1執行存盤程序
begin
p_up_sal;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/208444.html
標籤:其他
上一篇:SQL陳述句實作水仙花數求取
下一篇:Java 后臺開發面試題分享八
