Chapter 15

A1:
declare 
 a number; 
begin 
 a := 10 / 0; 
exception 
 when zero_divide then 
 dbms_output.put_line (‘YOU HAVE ATTEMPTED TO DIVIDE A NUMBER 
                         BY ZERO’); 
end; 
/ 
A2:
declare 
 bad_payroll_number      exception; 
 pragma exception_init (bad_payroll_number,–02291); 
begin 
 insert into tools (fk_payroll_number, tool_name, purchase_date) 
 values (987,‘PLIERS’,‘08-APR-98’); 
exception 
 when bad_payroll_number then 
 dbms_output.put_line (‘You have violated the payroll number constraint’); 
end; 
/ 
A3:
begin 
 insert into emp_tools (fk_payroll_number, tool_name, purchase_date) 
 values (987,‘PLIERS’,‘08-APR-98’); 
exception 
 when others then 
   dbms_output.put_line (‘You have violated the payroll number constraint’); 
end; 
/ 
A4:
 declare lname employee.last_name%type; ...

Get Oracle SQL and PL/SQL Handbook: A Guide for Data Administrators, Developers, and Business Analysts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.