Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Programming PL SQL.

Similar presentations


Presentation on theme: "Database Programming PL SQL."— Presentation transcript:

1 Database Programming PL SQL

2 Handling Exceptions with PL/SQL
• Exception: is an error that occur at run time (during program execution). When an exception occurs, the PL/SQL block is terminated. • An exception can be raised: – Implicitly by the Oracle server. – Explicitly by the program.

3 Handling Exceptions with PL/SQL
1. Implicitly by the Oracle server: When an oracle error occurs, an associated exception is raised automatically. The exception being raised is a predefined exception. Ex. when no rows are retrieved from the database in a SELECT statement, then PL/SQL raises the exception NO-DATA-FOUND. 2. Explicitly by the program: Explicitly raise an exception by issuing the RAISE statement within the block. The exception being raised may be either user defined or predefined.

4 Example BEGIN EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE ('A SELECT...INTO did not return any row.'); WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT.PUT_LINE ('A SELECT...INTO return multiple rows.'); WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE ('A SELECT...INTO raise an exception.'); END;

5 Evaluation The user should enter 3 num. not >10 … sort them declare
a number(3); b number(3); c number(3); f number(3); s number(3); t number(3); e exception; begin a := :a; b := :b; c := :c; if a>10 then RAISE e; END if; if b>10 then if c>10 then if a>b and a>c then f:=a; if b>c then s:=b; t:=c; else s:=c; t:=b; end if; elsif b>a and b>c then f:=b; if a>c then s:=a; t:= c; t:=a; elsif c>a and c>b then f:=c; if a>b then t:= b; DBMS_OUTPUT.PUT_LINE(f || s || t); EXCEPTION When e Then DBMS_OUTPUT.PUT_LINE('Numbers >10 are not acceptable!'); End; The user should enter 3 num. not >10 … sort them

6 Evaluation Write pl sql anonyms block which produces the entire Multiplication Table, like:


Download ppt "Database Programming PL SQL."

Similar presentations


Ads by Google