I'm writing a procedure, and i need to check whether my select query returned an empty record or not. (In this example whether there is no x,y shelf)
How can i do that?
I tried this:
temp shelves.loadability%TYPE := NULL; BEGIN select loadability into temp from shelves where rownumber = x and columnnumber = y; IF temp IS NOT NULL THEN /* do something when it's not empty */ ELSE /* do the other thing when it's empty */ END IF; But the second branch of the if never works...
EDIT:
Oh, it was so easy...
temp shelves.loadability%TYPE; BEGIN select count(*) into temp from shelves where rownumber = x and columnnumber = y; IF temp != 0 THEN /* do something when it's not empty */ ELSE /* do the other thing when it's empty */ END IF; END;
The IS EMPTY function provides an alternative syntax to IS_EMPTY and also returns TRUE if that set is empty. where set is a set of any set data type, such as a multi-assign double attribute. The results of this example would the same as the previous IS_EMPTY example.
Use the IS [NOT] EMPTY conditions to test whether a specified nested table is empty, regardless whether any elements of the collection are NULL . The condition returns a boolean value: TRUE for an IS EMPTY condition if the collection is empty, and TRUE for an IS NOT EMPTY condition if the collection is not empty.
Introduction to the Oracle IS NULL operatorIt is a marker for missing information or the information is not applicable. NULL is special in the sense that it is not a value like a number, character string, or datetime, therefore, you cannot compare it with any other values like zero (0) or an empty string (”).
It takes any number of arguments, and returns the first one which is not NULL. If all the arguments passed to COALESCE are NULL, it returns NULL. In contrast to NVL , COALESCE only evaluates arguments if it must, while NVL evaluates both of its arguments and then determines if the first one is NULL, etc.
Use an exception handler
Begin select column into variable from table where ...; -- Do something with your variable exception when no_data_found then -- Your query returned no rows -- when too_many_rows -- Your query returned more than 1 row -- end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With