create [ or replace ] procedure <procedure_name> [ (<argument_1> [mode] <datatype>, <argument_2> [mode] <datatype>, : )] -- procedure specification is | as -- declarartions begin <pl

/ sql block> --- procedure body end [< procedure_name>]; create or replace procedure raise_sal (vempno emp.empno%type,vincr number) is vsal emp.sal%type; begin select sal into vsal from emp where empno = vempno; if vsal > 4000 then dbms_output.put_line('--incremented not needed'); else update emp set sal = sal+vincr where empno = vempno; dbms_output.put_line('--incremented successfull'); end if; end; create or replace procedure avg_sal1 (vdeptavg in out number) is begin select avg(sal) into vdeptavg from emp where deptno = vdeptavg; end;

declare vdept number(2):= 10; begin avg_sal1(vdept); dbms_output.put_line('--average salary of dept is '||vdept); end;

create or replace function get_avgsal ( vdeptno number) return number is begin vsal number(7,2);

select avg(sal) into vsal from emp where deptno = vdeptno; return vsal; end;

create or replace package emp_pack as procedure raise_sal(vempno emp.empno%type,vincr number); function get_avgsal(vdeptno emp.deptno%type) return number; end;

create or replace package body emp_pack as procedure raise_sal(vempno emp.empno%type,vincr number) is vsal emp.sal%type; begin select sal into vsal from emp where empno = vempno; if vsal > 4000 then dbms_output.put_line('--incremented not needed'); else update emp set sal = sal+vincr where empno = vempno; dbms_output.put_line('--incremented successfull'); end if; end raise_sal; function get_avgsal(vdeptno emp.deptno%type) return number is vsal number(7,2); begin select avg(sal) into vsal from emp where deptno = vdeptno; return vsal; end get_avgsal; end;

create [or replace] trigger <trigger_name> [ before | after ] [ delete | [or] insert | [or] update [ of < column1>, [<column2> �. ] on <table_name> [ for each row [when <condition>]] begin �. -- pl/sql code �. end;

create or replace trigger my_emp_trig before update of sal on my_emp for each row begin if :new.sal > 6000 then raise_application_error(-20001,'--updation not successfull'); end if; end;

create or replace trigger transact_trig before update or insert or delete on my_emp begin if (trim(to_char(sysdate,'day'))='saturday') then raise_application_error(-20002,'--no tansactions on saturday'); end if; end;

create or replace trigger logchanges before insert or update or delete on logtable for each row declare v_changetype char(1); begin if inserting then v_changetype := `i�; -- some code here elsif updating then v_changetype := `u�; -- some code here else v_changetype := `d�; -- some code here end if; � � end logchanges;

create or replace trigger logchanges before insert or update or delete on my_emp for each row declare v_changetype char(1); begin if inserting then v_changetype := 'i'; insert into logtable values (v_changetype,null,null,null); insert into logtable values (v_changetype,:new.empno,:new.ename,:new.sal); elsif updating then v_changetype := 'u'; insert into logtable values (v_changetype,:old.empno,:old.ename,:old.sal); insert into logtable values (v_changetype,:new.empno,:new.ename,:new.sal); else v_changetype := 'd'; insert into logtable values (v_changetype,:old.empno,:old.ename,:old.sal); insert into logtable values (v_changetype,null,null,null); end if; end logchanges;

Sign up to vote on this title
UsefulNot useful