PL SQL ( NO_DATA_FOUND exception)
843389Feb 28 2011 — edited Feb 28 2011I have the following chunk of code, which could return no rows, one row or many rows. When it
returns one or many rows the DBMS_OUTPUT.PUT_LINE prints out my values.
When no data is found 'Hello' is not printed?
1) Can somebody explain to me why this is happening?
2) Suggest a way I can change the code to make the exception print when no data is found?
SET SERVEROUTPUT ON;
BEGIN
FOR prec IN ( select * from xxx.part_maint where drop_partition = 'Y' )
LOOP
DBMS_OUTPUT.PUT_LINE (prec.SCHEMA_NAME || ' ' || prec.OBJECT_NAME);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('hello');
END;