today:
23,592
yesterday:
36,697
Total:
9,614,825

Oracle APEX SQL

SQL NVL

admin 2016.05.19 15:08 Views : 1326

NVL

Syntax

Description of nvl.gif follows
Description of the illustration nvl.gif

Purpose

NVL lets you replace null (returned as a blank) with a string in the results of a query. If expr1 is null, then NVL returns expr2. If expr1 is not null, then NVL returns expr1.

The arguments expr1 and expr2 can have any datatype. If their datatypes are different, then Oracle Database implicitly converts one to the other. If they are cannot be converted implicitly, the database returns an error. The implicit conversion is implemented as follows:

  • If expr1 is character data, then Oracle Database converts expr2 to the datatype of expr1 before comparing them and returns VARCHAR2 in the character set of expr1.

  • If expr1 is numeric, then Oracle determines which argument has the highest numeric precedence, implicitly converts the other argument to that datatype, and returns that datatype.

    See Also:

    Table 2-10, "Implicit Type Conversion Matrix" for more information on implicit conversion and "Numeric Precedence" for information on numeric precedence

Examples

The following example returns a list of employee names and commissions, substituting "Not Applicable" if the employee receives no commission:

SELECT last_name, NVL(TO_CHAR(commission_pct), 'Not Applicable')
   "COMMISSION" FROM employees
   WHERE last_name LIKE 'B%'
   ORDER BY last_name;
 
LAST_NAME                 COMMISSION
------------------------- ----------------------------------------
Baer                      Not Applicable
Baida                     Not Applicable
Banda                     .1
Bates                     .15
Bell                      Not Applicable
Bernstein                 .25
Bissot                    Not Applicable
Bloom                     .2
Bull                      Not Applicable
No. Subject Author Date Views
42 PRICE TABLE UPDATE admin 2025.07.12 1539
41 Monthly SUM admin 2023.05.22 1522
40 LOOP TABLE UPDATE admin 2023.05.19 1624
39 STARTUP admin 2022.09.01 1150
38 ACTION admin 2019.01.11 7792
37 SELECT last_name FROM admin 2018.12.12 1969
36 CREATE TABLE admin 2018.09.25 1652
35 VERY IMPORTANT admin 2018.06.26 1310
34 MISSIONARY_SUB admin 2018.06.25 1206
33 TABLE PRINT admin 2018.06.18 1357
32 GP PRINT admin 2018.05.31 2257
31 How to convert DATE to NUMBER admin 2018.05.27 1341
30 DATE Compare admin 2018.05.22 1514
29 Oracle SQL Developer: Online Migration 3.1 admin 2018.04.25 1441
28 How to Update Oracle XE admin 2018.04.25 1226
27 SQL admin 2016.07.15 1693
26 SUBSTR admin 2016.05.26 1340
25 FOR LOOP admin 2016.05.20 1490
24 ROWNUM admin 2016.05.19 1365
» NVL admin 2016.05.19 1326