I have a query using a NVL on the where statement as follows:
CREATE TABLE fruits (
fruit_name VARCHAR2(100),
color VARCHAR2(100)
)
INSERT ALL
INTO fruits(fruit_name, color)
VALUES ('Apple','Red')
INTO fruits(fruit_name, color)
VALUES ('Orange','Orange')
INTO fruits(fruit_name, color)
VALUES ('Banana','Yellow')
INTO fruits(fruit_name, color)
VALUES ('Cherry','')
INTO fruits(fruit_name, color)
VALUES ('','Purple')
SELECT 1 FROM dual;
Now, issue lies on the - real - possibility of having a null value on the NVL function, like this:
select distinct
*
from fruits
where
fruit_name = nvl(:MY_VARIABLE, fruit_name)
When MY_VARIABLE is null the result would be:
FRUIT_NAME COLOR
Apple Red
Orange Orange
Banana Yellow
Cherry -
Row with the color 'Purple' was not listed here. Is there any workaround to avoid this and get the 'Purple' row on the results as well? (returning all values)
Yes, No Value Found will replace and use the specified column when null is found. But is there a way to use it (or any other) that allows to bring all the values including null?
Thanks