PL/SQL No_data_found

The No_data_found exception is an predefined exception of PL/SQL language.

No_data_found example 1

declare
	v_name varchar2(100);
begin
	select first_name into v_name 
	from students 
	where student_id=10000; 
exception
	when no_data_found then
	dbms_output.put_line('No student found!');
end;

Output:

No student found!

No_data_found example 2

declare
	v_name varchar2(100);
	v_order_id number;	
begin
	select name into v_name from course where course_id=2; 
	dbms_output.put_line('Course name: '||v_name);
	begin
		select order_id into v_order_id from orders where course_id=2;
		dbms_output.put_line('Order id is: '||v_order_id);
	exception
	when no_data_found then
		dbms_output.put_line('No order found for '||v_name);
	end;	
exception
	when no_data_found then
	dbms_output.put_line('No course found!');
end;

Output:

Course name: SQL 2

No order found for SQL 2