PL/SQL Others

The others exception is an predefined exception of PL/SQL language and catch any predefined exceptions.

Others example 1

declare
	v_order_id number;	
begin
	select order_id into v_order_id from orders where course_id=1234567;
	dbms_output.put_line('Order id is: '||v_order_id);
exception
	when others then
	dbms_output.put_line('When others exception error message: '||sqlerrm);
end;

Output:

When others exception error message: ORA-01403: no data found

Others example 2

declare
	v_order_id number;	
begin
	select order_id into v_order_id from orders where course_id=5;
	dbms_output.put_line('Order id is: '||v_order_id);
exception
	when others then
	dbms_output.put_line('When others exception error message: '||sqlerrm);
end;

Output:

When others exception error message: ORA-01422: exact fetch returns more than requested number of rows