Important
The SingleStore 9.1 release candidate (RC) is available now. It will be promoted to general availability (GA) soon and at that time it will be renamed to SingleStore 10.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10, while SingleStore 9.0 is recommended for production workloads.
NVL and IFNULL
On this page
The NVL() and IFNULL() functions evaluate whether an expression is NULL.NULL, the specified replacement expression is evaluated, and its value is returned.
The NVL and IFNULL functions are synonyms.NVL and IFNULL.
Syntax
NVL ( expression_to_check, expression_if_null )Arguments
expression_
An expression that evaluates to a value of any data type.NVL checks if this value is NULL, and if so, evaluates expression_ and returns the result.
expression_
An expression that evaluates to a value of any data type.NVL returns this value if expression_ is NULL.
Remarks
If expression_ and expression_ have different data types, then NVL casts its return value as follows:
-
If
expression_contains character data,to_ check NVLcasts its return value toVARCHAR. -
if
expression_is numeric,to_ check NVLcasts its return value to the data type of the expression (expression_orto_ check expression_) that has the higher numeric precision.if_ null
Examples
The following example demonstrates the simplest case of calling NVL.
SELECT NVL(NULL, 'NULL value') AS 'result';
+------------+
| result |
+------------+
| NULL value |
+------------+The following example shows how to call NVL once per table row.
DROP DATABASE IF EXISTS singlestore_docs_example;CREATE DATABASE singlestore_docs_example;use singlestore_docs_example;CREATE TABLE person(name VARCHAR(80), state VARCHAR(40));INSERT INTO person VALUES ('John Jones', 'New York'), ('Mary Smith', NULL),('Ann Brown', NULL);SELECT name, NVL(state, 'Unknown') AS state FROM personORDER BY name;
+------------+----------+
| name | state |
+------------+----------+
| Ann Brown | Unknown |
| John Jones | New York |
| Mary Smith | Unknown |
+------------+----------+Last modified: