Lab 11.2 Exercises

11.2.1 Use EXCEPTION_INIT Pragma

In this exercise, you insert a record in the COURSE table. The original PL/SQL script does not contain any exception handlers, so you are asked to define an exception and add the EXCEPTION_INIT pragma.

Create the following PL/SQL script:

 -- ch11_2a.sql, version 1.0 SET SERVEROUTPUT ON BEGIN    INSERT INTO course       (course_no, description, created_by, created_date)    VALUES       (COURSE_NO_SEQ.NEXTVAL, 'TEST COURSE', USER, SYSDATE);    COMMIT;    DBMS_OUTPUT.PUT_LINE ('One course has been added'); END; 

Execute the script, and then answer the following questions:


What output is printed on the screen?


Explain why the script does not execute successfully.


Add a user-defined exception to the script, so that the error generated by the INSERT statement is handled.


Run the new version of the script. Explain the output produced by the new version of the script.

Oracle PL[s]SQL by Example
Oracle PL[s]SQL by Example
ISBN: 3642256902
Year: 2003
Pages: 289 © 2008-2017.
If you may any questions please contact us: