today:
19
yesterday:
158
Total:
1,001,273

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
126 LAST DAY SQL admin 2024.01.19 115
125 Null Display Value admin 2024.01.10 111
124 영수증 2023 file admin 2024.01.04 223
123 Column Data 일괄 추가 admin 2023.11.24 130
122 Using SQL*Plus to Unlock and Change Passwords admin 2023.06.04 150
121 Reversing Require HTTPS admin 2023.06.04 84
120 ipconfig admin 2023.06.03 67
119 127.0.0.1:8080/apex/ admin 2023.06.03 83
118 CHANGE TABLE NAME admin 2023.05.31 58
117 DATE -> DAY CONVERT SQL admin 2023.05.25 38
116 YEAR EXPRESSIONS admin 2023.05.25 34
115 GRAPH (BAR) SQL SAMPLE admin 2023.05.25 39
114 Monthly SUM admin 2023.05.22 37
113 INNER JOIN admin 2023.05.19 37
112 LOOP TABLE UPDATE admin 2023.05.19 50
111 Global pages admin 2023.05.09 40
110 ORACLE COLLECTION admin 2023.05.08 38
109 FINAL TEST admin 2023.05.08 44
108 GitHub.com/Oracle/APEX. admin 2023.05.04 40
107 TEST admin 2023.05.03 36