Vous êtes sur la page 1sur 4

1)Write a database trigger on EMP so that when an employee record is changed (Insert ,update or delete), the total salary

for corresponding department is changed accordingly in the DEP table!("ssume #"$ and DEP %& columns are not null)! "' create or replace trigger emp(sal(trigger after Insert,)pdate,Delete of sal on emp for each row* begin update deptartment set totalsal + (select sum(sal) from emp where deptno + 'emp!deptno * end* , -) Write a P$,#.$ program which prints the minimum salary of the employees so that if they are gi/en 101 of their salary as bonus , the total bonus amount does not e2ceed -000! "' declare /(sal emp!sal1type* begin select min(sal) into /(sal from emp where (sal 3 0!01) 4 -000* dbms(output!put(line (5Minimum #alary ' 5 66 /(sal)* end* , "lternate answer create or replace procedure Min(sal( sal in number) as begin declare bonus number(7,-)* bonus'+ 0!13sal* if bonus 4-000 then bonus '+ -000* end if sal '+ sal 8 bonus* dbms(output!put(line(sal)* end

9)Write a P$,#.$ bloc: that prints the details of the employees of a particular department! It ta:es the department no as user input! he bloc: should also print ;%& EMP$&<EE# =&> ?I# DEP">ME% @ if the department number is in/alid! "' declare /(deptname dept!dname1type* begin dbms(output!put(line (5Enter Department %umber 5)* select dname into /(deptname from dept where deptno + Adeptnumber* dbms(output!put(line (5Department %ame is ' 5 66 /(deptname)* end* , B)Write a pac:age EMP("C I&% which has the following specification "! " procedure ?I>E(EMP which ta:es employee details as input and returns EMPID which is generated by a seDuence! E! " procedure =I>E(EMP which ta:es employee id as input and deletes that employee! C! " procedure >"I#E(#"$ which ta:es EMPID and >"I#E"M% as input and raises the salary! ?andle the e2ceptions properly( If EMPID is missing print ;%o Employee =ound) Write a P$,#.$ bloc: to call the pac:age and add an employee, raise his salary and then fire him! Fi/e some in/alid data input and test the error handling! "' C>E" E P"CG"FE emp(action "# =)%C I&% hire(emp (ename H">C?">-,Iob H">C?">-,mgr %)MEE>,sal %)MEE>,comm %)MEE>,deptno %)MEE>) >E )>% I% EFE>* P>&CED)>E fire(emp (emp(id I% EFE>)* P>&CED)>E raise(sal (emp(id I% EFE>, amount %)MEE>)* E%D emp(action* C>E" E P"CG"FE E&D< emp(action "#

=)%C I&% hire(emp (ename H">C?">-,Iob H">C?">-,mgr %)MEE>,sal %)MEE>,comm %)MEE>,deptno %)MEE>) >E )>% I% EFE> I# new(empno I% EFE>* EEFI% #E$EC empno(seD!%EJ H"$ I% & new(empno =>&M dual* I%#E> I% & emp H"$)E# (new(empno, ename, Iob,mgr, #<#D" E, sal, comm, deptno)* >E )>% new(empno* E%D hire(emp* P>&CED)>E fire(emp (emp(id I% EFE>) I# EEFI% DE$E E =>&M emp W?E>E empno + emp(id* E%D fire(emp* P>&CED)>E raise(sa(emp(id I% EFE>, amount %)MEE>) I# current(salary %)MEE>* EEFI% #E$EC sal I% & current(salary =>&M emp W?E>E empno + emp(id* I= current(salary I# %)$$ ?E% >"I#E salary(missing* E$#E )PD" E emp #E sal + sal 8 amount W?E>E empno + emp(id* E%D I=* E%D raise(sal*

7) Write a program which displays the following lines!! KE%"ME4 I# " KL&E4 W&>GI%F I% DEP" ME% KD%"ME4 )%DE> KM"%"FE> %"ME4 D>"WI%F " #"$">< &= K#"$4 ! "' declare /(emp emp!ename1type* /(mgr emp!ename1type* /(Iob emp!Iob1type* /(sal emp!sal1type* /(deptname dept!dname1type* cursor c1 is select e1!ename ,e1!L&E ,dname, e-!ename, e1!sal from emp e1,emp e-,dept d where e1!mgr + e-!empno and e1!deptno+d!deptno* begin open c1* loop fetch c1 into /(emp,/(Iob,/(deptname,/(mgr,/(sal* e2it when c11notfound* dbms(output!put(line ( /(emp 66 5 Is " 5 66 /(Iob 66 5 wor:ing in department 5 66 /(deptname 66 5 under 5 66 /(mgr 66 5 drawing a salary of 5 66 to(char(/(sal) )* end loop* end* ,

Vous aimerez peut-être aussi