SQL - Cursor if no records not working
CREATE OR REPLACE procedure verify_data
IS
cursor c1 is
select
e.name
from
table3 e
where
id IN (select id from table1)
and id in (select id from table2);
BEGIN
if c1%notfound then
DBMS_OUTPUT.PUT_LINE('no records found');
end if;
FOR eData in c1
LOOP
DBMS_OUTPUT.PUT_LINE(eData.name);
END LOOP;
END;
/
My result will be output if there records. but if no record found, nothing is shown.. is there any exception handling or things i could do to make my output “No Records found” to be display if theres no record in the select statement.
Update:
I added after
END LOOP
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no records found');
and before END;
SQL> execute verify_data();
PL/SQL procedure successfully completed.
Not displaying also..
Before end; add following code
WHEN NO_DATA_FOUND THENDBMS_OUTPUT.PUT_LINE('no records found');