FedSQL provides the
IFNULL function to test for a null value and the NULLIF expression
to change a null value.
The IFNULL function
takes two expressions as arguments. If the first expression is a null
value, it returns the second expression. Otherwise, the function returns
the first value:
IFNULL(expression, return_value_if_null_expression)
If
the value of
expression is
null, the function returns the value of
return_value_if_null_expression.
In this example, all
book names are returned for the books that have an unknown value of
numCopies:
select bookName when ifnull(numCopies, 'T') = 'T';
The NULLIF expression
also takes two expressions as arguments. If the two expressions are
equal, the value that is returned is a null value. Otherwise, the
value that is returned is the first SQL expression:
NULLIF(expression, test_value_expression);
Here, if the value of
numCopies is a negative value, –1, it is replaced with a null
to indicate an unknown value:
update books set numCopies = nullif(numCopies, –1);