- Categorias:
IS [ NOT ] NULL¶
Determina se uma expressão é NULL ou não é NULL.
Sintaxe¶
<expr> IS [ NOT ] NULL
Retornos¶
Retorna BOOLEAN verdadeiro ou falso.
Exemplos¶
Criar e carregar a tabela:
CREATE OR REPLACE TABLE i (id NUMBER, col1 NUMBER, col2 NUMBER); INSERT INTO i (id, col1, col2) VALUES (1, 0, 5), (2, 0, null), (3, null, 5), (4, null, null);
Exibir os dados:
SELECT * FROM i ORDER BY id; +----+------+------+ | ID | COL1 | COL2 | |----+------+------| | 1 | 0 | 5 | | 2 | 0 | NULL | | 3 | NULL | 5 | | 4 | NULL | NULL | +----+------+------+
Usar IS NOT NULL
:
SELECT * FROM i WHERE col1 IS NOT NULL ORDER BY id; +----+------+------+ | ID | COL1 | COL2 | |----+------+------| | 1 | 0 | 5 | | 2 | 0 | NULL | +----+------+------+
Usar IS NULL
:
SELECT * FROM i WHERE col2 IS NULL ORDER BY id; +----+------+------+ | ID | COL1 | COL2 | |----+------+------| | 2 | 0 | NULL | | 4 | NULL | NULL | +----+------+------+
Usar uma combinação de IS NOT NULL
e IS NULL
:
SELECT * FROM i WHERE col1 IS NOT NULL OR col2 IS NULL ORDER BY id; +----+------+------+ | ID | COL1 | COL2 | |----+------+------| | 1 | 0 | 5 | | 2 | 0 | NULL | | 4 | NULL | NULL | +----+------+------+