Download presentation
Presentation is loading. Please wait.
Published byCharlotte Simon Modified over 9 years ago
1
Procedure Function Trigger
2
create table employee ( id number, name varchar2(100), deptno number, salary float, primary key(id) ) create table deptincrease ( deptno number, percentage number, primary key(deptno) ) EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage
3
EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace procedure raiseallsalary is cursor dept is select distinct deptno from deptincrease; deptval dept%ROWTYPE; dp number; begin for deptval in dept loop select percentage into dp from deptincrease where deptno=deptval.deptno; raisesalary(deptval.deptno,dp); end loop; end;
4
EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace procedure raisesalary(dept in number, percent in number) is cursor emp is select * from employee where deptno=dept; empval emp%ROWTYPE; newsalary float; begin open emp; loop fetch emp into empval; exit when emp%NOTFOUND; newsalary:=empval.salary + (empval.salary*percent)/100; update employee set salary=newsalary where id=empval.id; end loop; close emp; end;
5
EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace function getdeptsalary(dept number) return number is total number; begin total:= 0; for emp_sal in (select salary from employee where deptno = dept and salary is not null) loop total:= total + emp_sal.salary; end loop; return total; end;
6
EMPLOYEEidnamedeptnosalary DEPTINCREASEdeptnopercentage create or replace trigger eid_generate before insert on employee for each row declare cnt number; next number; begin select count(*) into cnt from employee; if cnt > 0 then select max(id) into next from employee; next:=next+1; :new.id:=next; else :new.id:=1; end if; end; Before insert or update After insert. :new :old
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.