Mathematical and string operations
The operations in this list always return NULL:
- 
1 + 2 + 3 + NULL
- 
5 * NULL - 7
- 
'Home ' || 'sweet ' || NULL
- 
MyField = NULL
- 
MyField <> NULL
- 
NULL = NULL
If you have difficulty understanding why, remember that NULL means “unknown”.You can also look at the following table where per-case explanations are provided.In the table we don’t write NULL in the expressions (as said, this is often illegal);instead, we use two entities A and B that are both NULL.A and B may be fields, variables, or even composite subexpressions — as long as they’re NULL, they’ll all behave the same in the enclosing expressions.
| If AandBareNULL, then: | Is: | Because: | 
|---|---|---|
| 
 | 
 | If  | 
| 
 | 
 | If  | 
| 
 | 
 | If  | 
| 
 | 
 | If  | 
| 
 | 
 | ...but you also can’t tell if  | 
| 
 | 
 | With  | 
Here is the complete list of math and string operators that return NULL if at least one operand is NULL:
- 
+,-,*, and/
- 
!=,~=, and^=(synonyms of<>)
- 
<,⇐,>, and>=
- 
!<,~<, and^<(low-precedence synonyms of>=)
- 
!>,~>, and^>(low-precedence synonyms of⇐)
- 
||
- 
[NOT] BETWEEN
- 
[NOT] STARTING WITH
- 
[NOT] LIKE
- 
[NOT] CONTAINING
The explanations all follow the same pattern: if A is unknown, you can’t tell if it’s greater than B;if string S1 is unknown, you can’t tell if it contains S2;etcetera.
Using LIKE with a NULL escape character would crash the server in Firebird versions up to and including 1.5.This bug was fixed in v.1.5.1.From that version onward, such a statement will yield an empty result set.