today:
16
yesterday:
158
Total:
1,001,270

SQL NVL

admin 2016.05.19 15:08 Views : 151

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
46 DATE Compare admin 2018.05.22 366
45 How to convert DATE to NUMBER admin 2018.05.27 198
44 GP PRINT admin 2018.05.31 918
43 TABLE PRINT admin 2018.06.18 186
42 eeeeee admin 2018.06.21 218
41 MISSIONARY_SUB admin 2018.06.25 199
40 IF/ELSE ... CASE WHEN admin 2018.06.25 209
39 VERY IMPORTANT admin 2018.06.26 225
38 Change Admin PASSWORD admin 2018.07.31 226
37 CREATE TABLE admin 2018.09.25 471
36 IMP admin 2018.10.08 717
35 SELECT last_name FROM admin 2018.12.12 742
34 ACTION admin 2019.01.11 6454
33 JK admin 2019.02.05 700
32 QRCODE admin 2020.05.25 405
31 How to Install Oracle 11g on Windows 10 - 64 bit | Download / Install Oracle 11g Database file admin 2022.03.17 120
30 SQL DEVELOPER file admin 2022.03.17 106
29 Forgot Oracle username and password, how to retrieve? admin 2022.03.18 151
28 SQL Developer Password change / EXPORT & IMPORT admin 2022.03.18 157
27 STARTUP admin 2022.09.01 83