The NVL function in MySQL is used to replace NULL values with specified default values. The syntax is NVL(expression, default_value). It can be used to: 1. Replace NULL values to avoid queries returning incomplete rows; 2. Fill in missing data for calculation or analysis; 3. Unify NULL values to a specific value when comparing or sorting. For example, NVL(name, 'Unknown Name') replaces a NULL name with "Unknown Name".
NVL function in MySQL
What is the NVL function?
The NVL function is a MySQL database function that replaces NULL values with a specified default value.
Syntax:
<code>NVL(expression, default_value)</code>
How to use the NVL function?
The NVL function can be used in the following scenarios:
Example:
<code class="sql">SELECT NVL(name, 'Unknown Name') FROM customers;</code>
This will return the names of all customers, if a customer's name is NULL, replace it with the string "Unknown Name" .
Note:
The above is the detailed content of nvl usage in mysql. For more information, please follow other related articles on the PHP Chinese website!