Null means “no value here”—unknown or not supplied. In DB2 for z/OS you cannot test that with ordinary equals. IS NULL and IS NOT NULL are the NULL predicate: the only search condition that is allowed to say yes or no about a null without sliding into UNKNOWN. This page is the practical companion to three-valued logic: how to write the predicate, how it differs from empty strings and blanks, and how programs use indicator variables.
IBM’s SQL Reference defines the NULL predicate as a test for null values:
1expression IS [NOT] NULL
The result cannot be unknown. If the expression is null, IS NULL is true; if it is not null, the result is false. IS NOT NULL reverses that. That is why WHERE can keep or drop rows reliably: unlike COMM = 0, this predicate never yields UNKNOWN.
A parameter marker must not be specified for or within the expression. You test a column, a host variable, an expression, or (in supported contexts) an array. You do not write ? IS NULL as the whole predicate in the way beginners sometimes try.
1234567SELECT EMPNO, LASTNAME, COMM FROM DSN8C10.EMP WHERE COMM IS NULL; SELECT EMPNO, LASTNAME, COMM FROM DSN8C10.EMP WHERE COMM IS NOT NULL;
IBM’s sample: PHONENO IS NULL is true whenever PHONENO has the null value, and false otherwise. Arrays can be null as a whole: MYARRAY IS NULL tests the array value, not whether an element is null.
For compatibility with other SQL dialects, Db2 allows ISNULL as an alternative for IS NULL and NOTNULL for IS NOT NULL. New z/OS SQL should use the two-word forms; they match the manuals, code reviews, and every IBM sample.
The equal operator compares two values. Null is not a value in that sense; any comparison that involves a null operand is UNKNOWN (except the special IS DISTINCT FROM predicate). WHERE and HAVING keep rows only when the search condition is TRUE.
1234567891011-- Wrong: never keeps null commissions WHERE COMM = NULL -- Wrong: also UNKNOWN when COMM is null WHERE COMM = 0 -- Right: missing commission WHERE COMM IS NULL -- Right: stored zero (a real number) WHERE COMM = 0
The same trap appears in ON, CHECK, CASE searched-when, and MERGE. If the business question is “missing,” write IS NULL. If the question is “equal to this known value,” write a basic predicate and accept that nulls will not match.
IS DISTINCT FROM is the null-aware equality test (two nulls are not distinct). Use it when you need “same including both null” without writing OR IS NULL pairs. For “is this column empty of data,” IS NULL remains the clear predicate.
IS NOT NULL means the expression has a value. That value might be zero, a blank string, a zero-length VARCHAR, or a real commission. It is not a test for “interesting” data.
1234SELECT EMPNO, LASTNAME FROM DSN8C10.EMP WHERE COMM IS NOT NULL AND COMM > 0;
Combining IS NOT NULL with a range is optional for WHERE COMM > 0, because a null COMM already fails the comparison. Writing both can still help readers and some access paths (COL IS NOT NULL is listed among stage-1 range-related predicates in performance summaries). Do not use IS NOT NULL as a substitute for a domain check: a CHAR column of all blanks is NOT NULL and still “empty” to the application.
This is the beginner mix-up that produces empty QMF reports.
| Test | NULL | VARCHAR '' | CHAR blanks |
|---|---|---|---|
| COL IS NULL | TRUE | FALSE | FALSE |
| COL IS NOT NULL | FALSE | TRUE | TRUE |
| COL = '' | UNKNOWN | TRUE (VARCHAR) | Depends on CHAR padding |
| COL = 0 | UNKNOWN | n/a (string) | n/a |
1234567891011-- Missing phone WHERE PHONENO IS NULL -- Present but blank CHAR (if the column is CHAR) WHERE PHONENO = '' -- or, more honestly for CHAR: WHERE PHONENO = ' ' -- width matches the column -- Present zero-length VARCHAR WHERE PHONENO = '' AND PHONENO IS NOT NULL;
Application copybooks often treat spaces as “no phone.” The database may store NULL, blanks, or a default. Agree on one convention. Mixing them means you need PHONENO IS NULL OR PHONENO = '' (and maybe TRIM) forever.
SELECT INTO and FETCH into a host variable that cannot represent null (a COBOL PIC without an indicator) fails with SQLCODE -305 when the column is null. Declare a SMALLINT indicator and test it after SQLCODE 0:
SQL PL and SQL procedures use IS NULL on SQL variables the same way. Do not compare a variable to the NULL keyword with equals.
After a LEFT OUTER JOIN, unmatched preserved rows have nulls on the other side. The usual anti-join pattern is:
12345SELECT D.DEPTNO, D.DEPTNAME FROM DSN8C10.DEPT D LEFT JOIN DSN8C10.EMP E ON E.WORKDEPT = D.DEPTNO WHERE E.EMPNO IS NULL;
Test a column that is NOT NULL in the inner table (primary key). Testing a nullable inner column cannot tell “no match” from “match with a null in that column.”
A column defined NOT NULL never needs IS NULL in queries against that column—the predicate would be false for every row. Nullable columns that you often search with IS NULL / IS NOT NULL can still use indexes; null handling in type-2 indexes is designed for this. Sparse “mostly null” columns sometimes belong in a separate table rather than a wide nullable column you always IS NOT NULL away.
Imagine lunch boxes. Some boxes have an apple (a real value). Some boxes have a note that says “apple not packed today” (NULL). Some boxes contain a crumpled empty bag (empty string). Asking “is the apple equal to nothing?” is a confusing riddle. Asking “is the not-packed note in the box?” (IS NULL) is a yes/no question. Empty bags are still bags. Blank CHAR fields are boxes stuffed with packing peanuts so they look full but have no apple.
No. Null is a property of a value (or the absence of one). Columns have types and may allow nulls unless NOT NULL was specified.
Yes. SALARY + COMM IS NULL is true if either operand is null (null arithmetic yields null). That is different from testing the two columns separately.
COUNT(*) counts rows, including rows whose other columns are null. COUNT(COL) ignores nulls in COL. COUNT(*) WHERE COL IS NULL counts rows where that column is null.
1. How do you test whether a column is null in Db2?
2. Can the result of IS NULL be UNKNOWN?
3. Does WHERE COMM = 0 find rows where COMM is null?
4. Is a zero-length VARCHAR the same as NULL?
5. What are ISNULL and NOTNULL?