To catch the NO_DATA_FOUND exception, NO_DATA_FOUND your code as follows by adding the exception section:
DECLARE VAR_SUPP_NM VARCHAR2(100); VAR_SUPP_ID NUMBER := 1; WHILE_VAR CHAR := 'Y'; BEGIN SELECT SUPP_NM INTO VAR_SUPP_NM FROM TEST.SUPPLIER WHERE SUPP_ID = VAR_SUPP_ID; DBMS_OUTPUT.PUT_LINE('DATA FOUND'); exception when no_data_found then DBMS_OUTPUT.PUT_LINE('SQL DATA NOT FOUND'); END;
Checking SQL%FOUND or SQL%NOTFOUND does not make sense in the case of the select into statement, because if the select statement does not return any rows, it will always throw a NO_DATA_FOUND exception, in addition, if this select statement calls the aggregate function, it will always return data or null if no row is selected.
Do not use the varchar data type, use the varchar2 data type varchar2 .
Nick Krasnov
source share