Exec Ption

You might also like

You are on page 1of 3

List no 8:- Write a Procedure demonstrating the use of Exception.

Roll no ----- 06 CREATE OR REPLACE PROCEDURE error_proc AS n number; n_great exception; BEGIN n:=5; if(n>4) then raise n_great; else dbms_output.put_line('n is less then to 4'); end if; exception when n_great then dbms_output.put_line('n is greater then to 5'); END; set serveroutput on; execute error_proc;

-:OUTPUT:n is greater then to 5 PL/SQL procedure successfully completed

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~

/////////////////////////////////// create table exception_amar(sals_no number(5), sals_target number(7), commission number(5), salary number(6)); desc exception_amar

insert into exception_amar values(11, 200, 5, 3000); insert into exception_amar values(12, 500, 7, 3000); insert into exception_amar values(13, 700, 9, 3000); insert into exception_amar values(14, 900, 11, 3000); select * from exception_amar;

CREATE OR REPLACE PROCEDURE error_proc AS salesman_no exception_amar.sals_no%type; target exception_amar.sals_target%type; comm exception_amar.commission%type; sal exception_amar.salary%type; n number(5); error_exp exception; BEGIN select sals_no into n from execption_amar where sals_target<=700 RAISE error_exp; EXCEPTION when error_exp then insert into exception_amar(sal, salary+(salary*0.4)); END;

Name SALS_NO SALS_TARGET COMMISSION SALARY

Null? NUMBER(5) NUMBER(7) NUMBER(5) NUMBER(6)

Type

SALS_NO 11 12 13

SALS_TARGET 200 500 700

COMMISSION 5 7 9

SALARY 3000 3000 3000

14

900

11

3000

/////////////////////////////////////////////////////111111111111111111111111///////////////////

You might also like