Skip to main content

Use NULL-related functions in queries

This topic provides examples of how to identify and convert NULL values in queries by using NULL-related functions.

A NULL value is not equal to or not equal to any value. You can use the IS NULL clause to identify a NULL value. You can also use the NVL() function to convert a NULL value to a recognizable string.

Examples

Create a sample table and insert appropriate data.

CREATE TABLE t_null(id NUMBER NOT NULL PRIMARY KEY, name VARCHAR(10));
Query OK, 0 rows affected

INSERT INTO t_null(id, name) VALUES(1,'A'), (2,NULL), (3,'NULL');
Query OK, 3 rows affected
Records: 3 Duplicates: 0 Warnings: 0

Use the NVL() or IFNULL() function to identify and convert NULL values. In seekdb, if a column may contain NULL values, you can use the NVL() or IFNULL() function to identify and convert the NULL values to special characters.

SELECT id, name, NVL(name, 'NOT APPLICABLE') n_name, IFNULL(name, 'NOT APPLICABLE') n2_name FROM t_null;
+----+------+----------------+----------------+
| id | name | n_name | n2_name |
+----+------+----------------+----------------+
| 1 | A | A | A |
| 2 | NULL | NOT APPLICABLE | NOT APPLICABLE |
| 3 | NULL | NULL | NULL |
+----+------+----------------+----------------+
3 rows in set