STATE THE OUTPUT In Exception Handling


--1> STATE THE OUTPUT

DECLARE
stock_price   number := 9.73;
NET_EARNINGS NUMBER:=0;
PE_RATIO NUMBER;

BEGIN
    PE_RATIO := STOCK_PRICE/NET_EARNINGS;
    DBMS_OUTPUT.PUT_LINE('PRICE/EARNING RATIO='||PE_RATIO);
EXCEPTION
   WHEN ZERO_DIVIDE THEN
     DBMS_OUTPUT.PUT_LINE('COMPANY HAD ZERO EARNING ');
     PE_RATIO:=NULL;
END;
 

--2> STATE THE OUTPUT

DECLARE
C_ID CUSTOMER.ID%TYPE:=&C_ID;
C_NAME CUSTOMER.FIRST%TYPE;
C_ADDR CUSTOMER.ADDRESS%TYPE;

EX_INVALID_ID EXCEPTION;
BEGIN
IF C_ID<=0 THEN
  RAISE EX_INVALID_ID;
ELSE
  SELECT FIRST,ADDRESS INTO C_NAME,C_ADDR FROM CUSTOMER WHERE ID=C_ID;
  DBMS_OUTPUT.PUT_LINE('NAME: '||C_NAME);
  DBMS_OUTPUT.PUT_LINE('ADDRESS: '||C_ADDR);
END IF;

EXCEPTION
WHEN EX_INVALID_ID THEN
 DBMS_OUTPUT.PUT_LINE('ID MUST BE GREATER THAN 0!');
WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('NO SUCH CUSTOMER ');
WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('ERROR!');
END;

Previous
Next Post »