With PL/SQL, I perform a SELECT INTO statement, based on the result I would like to perform the same logic. I would like to check for:
- no result (0 rows returned)
- empty result (1 row with '' returned)
- null result (1 row with null returned)
In my current solution, I use a NO_DATA_FOUND exception for case 1 and IF checks for case 2+3, but call the same logic in either way, which I don't like:
BEGIN
SELECT some_value
INTO my_variable
FROM some_table
WHERE somecheck = 123
IF my_variable IS NULL OR my_variable = ''
THEN
##perform logic##
END IF;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
##perform same logic as above##
END;
Can this be solved somehow better to prevent that I have to copy paste the same code for both, my IF check and my exception?
In particular, is it safe to extend my IF checks with
IF SQL%ROWCOUNT = 0 THEN ...
instead of using NO_DATA_FOUND exception to achieve my goals?