Some DBMSs provide an NVL()
function, which can be used when working with potentially NULL values. The function allows us to replace any NULL values with another value.
Tag: functions
SQL ISNULL() Explained
Some RDBMSs provide an ISNULL()
function that can be used when dealing with potentially null values.
MySQL, MariaDB, and Oracle Database each have an ISNULL()
function that returns 1
if its argument is null
, and 0
if it’s not.
SQL Server also has an ISNULL()
function, but it works differently. It works more like how the IFNULL()
function works in some other RDBMSs.
Other RDBMSs, such as PostgreSQL and SQLite don’t include an ISNULL()
function, but they do support the IS NULL
predicate (as do the other RDBMSs).
PostgreSQL COALESCE() Explained
In PostgreSQL, the COALESCE()
operator returns the first non-null value from its list of arguments. If all arguments are null
, it returns null
.
SQL IFNULL() Explained
Some RDBMSs provide an IFNULL()
function that can be used when dealing with potentially null values. In particular, MySQL, MariaDB, and SQLite each have an IFNULL()
function that replaces any null values with another value.
Other RDBMSs, such as SQL Server, Oracle, and PostgreSQL provide similar functionality via functions of a different name.
Continue readingHow ISNULL() Works in MariaDB
In MariaDB, the ISNULL()
function checks whether an expression is null
or not. If the expression resolves to null
, then ISNULL()
returns 1
, otherwise it returns 0
.
GREATEST() Function in PostgreSQL
In PostgreSQL, the GREATEST()
function returns the greatest (or largest) value from a list of any number of expressions.
The GREATEST()
function is not included in the SQL standard, but it’s a popular extension that many major RDBMSs support.
SQL NULLIF() Explained
Most major RDBMSs support the NULLIF()
operator, which returns NULL
if both of its arguments are equivalent. If the arguments not equivalent, NULLIF()
returns the first argument.
NULLIF()
is a SQL-standard feature (it’s included in the ISO/IEC 9075 specification).
SQL COALESCE() Explained
Most major RDBMSs support the COALESCE()
operator, which returns the first non-null value from its list of arguments.
COALESCE()
is a SQL-standard feature (it’s included in the ISO/IEC 9075 specification).
LEAST() Function in PostgreSQL
In PostgreSQL, the LEAST()
function returns the smallest value from a list of any number of expressions.
The LEAST()
function is not included in the SQL standard, but it’s a popular extension that many major RDBMSs support.
MariaDB NULLIF() Explained
In MariaDB, the NULLIF()
function returns NULL
if both of its arguments are equivalent. Otherwise it returns the first argument.