Null Values
The value NULL indicates the absence of a value. It is a placeholder for a value that is missing. Use a NULL when the actual value is not known or when a value would not be meaningful. Do not use NULL to represent a numeric value of zero, because they are not equivalent. Any parameter in an expression can contain NULL regardless of its data type. In addition, any column in a table can contain NULL, regardless of its data type, unless you specify NOT NULL or PRIMARY KEY integrity constraints for the column when you create the table.
The following properties of NULL affect operations on rows, parameters, or local variables:
-
By default,
NULLis sorted as the highest value in a sequence of values. However, you can modify the sort order value forNULLwithNULLS FIRSTorNULLS LASTin theORDER BYclause. -
Two
NULLvalues are not equal to each other except in aGROUP BYorSELECT DISTINCToperation. -
An arithmetic expression containing a
NULLevaluates toNULL. In fact, all operators (except concatenation) returnNULLwhen given aNULLoperand. For example,(5-col), wherecolisNULL, evaluates toNULL. -
To test for
NULL, use the comparison conditionsIS NULLorIS NOT NULL. BecauseNULLrepresents a lack of data, aNULLcannot be equal or unequal to any value or to anotherNULL. Thus, the statementselect * from employees where mgr_id = NULLevaluates to 0, since you cannot use this comparison toNULL. However, the statementselect * from employees where mgr_id is NULLprovides the CEO of the company, since that is the only employee without a manager. For details, see "IS NULL Predicate". -
You can use the
NULLvalue itself directly as an operand of an operator or predicate. For example, the(1 = NULL)comparison is supported. This is the same as if you castNULLto the appropriate data type, as follows:(1 = CAST(NULL AS INT)). Both methods are supported and return the same results.
Because of these properties, TimesTen ignores columns, rows, or parameters containing NULL when:
-
Joining tables if the join is on a column containing
NULL. -
Executing aggregate functions.
In several SQL predicates, you can explicitly test for NULL. APIs supported by TimesTen offer ways to handle null values. For example, in an ODBC application, use the functions SQLBindCol, SQLBindParameter, SQLGetData, and SQLParamData to handle input and output of NULL values.