This topic provides specific examples on how to use NULL-related functions to define and convert NULL values.
NULL-related functions are used to handle NULL values. A NULL value cannot be equal or unequal to any numeric value. To determine whether a value is NULL, you can use the IS NULL operator or use the NVL() function to convert a NULL value into a user-defined string.
Examples
Convert a NULL value. In an Oracle tenant, if a column may contain NULL values, you can use the NVL() or NVL2() function to detect and convert the NULL values. Execute the following SQL statements:
Create a table named
t_null.obclient> CREATE TABLE t_null(id number NOT NULL PRIMARY KEY, name varchar(10)); Query OK, 0 rows affectedInsert data into the
t_nulltable.obclient> INSERT INTO t_null(id, name) values(1,'A'), (2,NULL), (3,'NULL'); Query OK, 3 rows affected Records: 3 Duplicates: 0 Warnings: 0Query the
t_nulltable, and use theNVL()orNVL2()function to convert special characters.obclient> SELECT id, name, nvl(name, 'NOT APPLICABLE') n_name, nvl2(name, 'NOT NULL', 'NOT APPLICABLE') n2_name FROM t_null; +----+------+----------------+----------------+ | ID | NAME | N_NAME | N2_NAME | +----+------+----------------+----------------+ | 1 | A | A | NOT NULL | | 2 | NULL | NOT APPLICABLE | NOT APPLICABLE | | 3 | NULL | NULL | NOT NULL | +----+------+----------------+----------------+ 3 rows in set