The too_many_rows exception is an predefined exception of PL/SQL language.
Too_many_rows example 1
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 too_many_rows then
dbms_output.put_line('Tow many rows!');
end;
Output:
Tow many rows!
Too_many_rows 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 too_many_rows then
begin
select order_id into v_order_id
from orders where course_id=5 and rownum=1;
dbms_output.put_line('Order id is: '||v_order_id);
end;
end;
Output:
Order id is: 2