----Block 1
SET serveroutput ON
DECLARE
e_id employee.emp_id%type;
BEGIN
SELECT emp_id INTO e_id FROM employee WHERE emp_id = 'EEEE';
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No data found for the input Employee Id');
WHEN OTHERS THEN
dbms_output.put_line('No data found for the input Employee Id--Others block!!!');
END;
/
Output:
anonymous block completed
No data found for the input Employee Id
----Block 2
SET serveroutput ON
DECLARE
e_id employee.emp_id%type;
BEGIN
SELECT emp_id INTO e_id FROM employee WHERE emp_id = 'EEEE';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('No data found for the input Employee Id--Others block!!!');
WHEN no_data_found THEN
dbms_output.put_line('No data found for the input Employee Id');
END;
/
Error report:
ORA-06550: line 6, column 1:
PLS-00370: OTHERS handler must be last among the exception handlers of a block
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Conclusion:
Exception block should always have the 'OTHERS' listed the last in the list
SET serveroutput ON
DECLARE
e_id employee.emp_id%type;
BEGIN
SELECT emp_id INTO e_id FROM employee WHERE emp_id = 'EEEE';
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No data found for the input Employee Id');
WHEN OTHERS THEN
dbms_output.put_line('No data found for the input Employee Id--Others block!!!');
END;
/
Output:
anonymous block completed
No data found for the input Employee Id
----Block 2
SET serveroutput ON
DECLARE
e_id employee.emp_id%type;
BEGIN
SELECT emp_id INTO e_id FROM employee WHERE emp_id = 'EEEE';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('No data found for the input Employee Id--Others block!!!');
WHEN no_data_found THEN
dbms_output.put_line('No data found for the input Employee Id');
END;
/
Error report:
ORA-06550: line 6, column 1:
PLS-00370: OTHERS handler must be last among the exception handlers of a block
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Conclusion:
Exception block should always have the 'OTHERS' listed the last in the list
Comments