12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Handling PL/<strong>SQL</strong> ErrorsExample 7–31Continuing After an Exception-- create a temporary table for this exampleCREATE TABLE employees_temp ASSELECT employee_id, salary, commission_pct FROM employees;DECLAREsal_calc NUMBER(8,2);BEGININSERT INTO employees_temp VALUES (303, 2500, 0);BEGIN -- sub-block beginsSELECT salary / commission_pct INTO sal_calc FROM employees_tempWHERE employee_id = 303;EXCEPTIONWHEN ZERO_DIVIDE THENsal_calc := 2500;END; -- sub-block endsINSERT INTO employees_temp VALUES (304, sal_calc/100, .1);EXCEPTIONWHEN ZERO_DIVIDE THENNULL;END;/-- view the resultsSELECT * FROM employees_temp WHERE employee_id = 303 OR employee_id = 304;-- drop the temporary tableDROP TABLE employees_temp;In this example, if the SELECT INTO statement raises a ZERO_DIVIDE exception, thelocal handler catches it and sets sal_calc to 2500. Execution of the handler iscomplete, so the sub-block terminates, and execution continues with the INSERTstatement.PL/<strong>SQL</strong>: Usage Information 7-25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!