today:
131
yesterday:
311
Total:
1,018,370

SQL NVL

admin 2016.05.19 15:08 Views : 175

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 Global pages admin 2023.05.09 48
125 YEAR EXPRESSIONS admin 2023.05.25 48
124 FINAL TEST admin 2023.05.08 51
123 ORACLE COLLECTION admin 2023.05.08 52
122 TEST admin 2023.05.03 53
121 GitHub.com/Oracle/APEX. admin 2023.05.04 53
120 DATE -> DAY CONVERT SQL admin 2023.05.25 54
119 GRAPH (BAR) SQL SAMPLE admin 2023.05.25 56
118 INNER JOIN admin 2023.05.19 58
117 TEST admin 2023.04.28 61
116 GP 영수증 (3) -01/04/2023 admin 2023.01.04 65
115 WHDR email address admin 2023.04.13 67
114 Monthly SUM admin 2023.05.22 67
113 GP - 영수증 (2) admin 2022.11.07 71
112 GP 영수증 본문 admin 2022.11.07 72
111 CHANGE TABLE NAME admin 2023.05.31 73
110 Building Mobile Applications with Oracle Application Express 5.0 admin 2017.11.25 75
109 ipconfig admin 2023.06.03 78
108 LOOP TABLE UPDATE admin 2023.05.19 79
107 Manufacturing resource planning (MRP II) admin 2018.02.14 83