Friday, January 01, 2010

There's Nothing like NULLs for Confusion

Happy New Year everyone. Here is a cautionary note about using NULLs and the 'NULL' string with Discoverer. If you want to select rows containing NULLs you need to use the condition IS NULL. However, this causes a problem if you want to select null values using a parameter because the condition column=:parameter would not return any rows if the parameter was NULL.

Before 10gR2, Discoverer did not handle selecting null values from a parameter so you needed to convert the NULL values into a NULL string and include the the NULL string in the list of values. So for example, if you had a column that contained the values 'YES', 'NO' and NULL you would create a list of values that returned the strings 'YES', 'NO' and 'NULL' then use a condition NVL(column, 'NULL') = :parameter. So when you wanted to select rows where the column contained 'YES' or was NULL, you selected 'YES' and 'NULL' from the list of values and Discoverer generated the condition NVL(column, 'NULL') IN ('YES', 'NULL') returning the correct rows (assuming your column did not actually contain any 'NULL' strings).

So far so good, but this changed with Discoverer Plus 10gR2. In this release Discoverer tried to deal with the NULL value in the list of values. So if you had 'NULL' in the list of values it would create an IS NULL condition. So in the above example you could use the conditioncolumn = :parameter and if you selected 'YES' and 'NULL' from the list of values Discoverer would generate the condition column IN ('YES') OR column IS NULL.

Great, but this release would change the 'NULL' string to NULL anywhere it was entered into a condition. So for example, if you entered the condition column = 'NULL' it would change it to column IS NULL. Also if you had the condition NVL(column, 'NULL') = 'NULL' it would change it to NVL(column,NULL) IS NULL. This would give you unexpected results and to add to the confusion, Discoverer Desktop continues to work as before so the results would be different from the Desktop edition.

However, the confusion is compounded in Discoverer Plus 10gR2 CP6. In this consolidated patchset the functionality changes yet again. Discoverer Plus nolonger converts the condition column='NULL' so Plus now returns the correct results. However it stores the condition internally as column = '''NULL''' and when you open and run the workbook in Discoverer Desktop the condition column = '''NULL''' is used so again you get different results. There are more differences when you create the conditions in Desktop and open the same workbook in Plus.

One would hope that with a product with the longevity of Discoverer the basic functionality of the product would be stable, but NULLs are nothing and nothing changes like 'NULL's.

No comments:

Followers