today:
142
yesterday:
177
Total:
1,001,059

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
41 Monthly SUM admin 2023.05.22 37
40 LOOP TABLE UPDATE admin 2023.05.19 50
39 STARTUP admin 2022.09.01 83
38 EMPLOYEE_LEVEL_ID admin 2016.05.03 88
37 Display Value, Return Value admin 2016.05.10 115
36 Oracle SQL Developer: Online Migration 3.1 admin 2018.04.25 120
35 LIST OF VALUE (DYNAMIC) admin 2016.04.28 126
34 Global & Custom Serach file admin 2016.04.28 127
33 HEAD TITLE (제목)을 조건에 따라 바꾸기 admin 2016.05.03 132
32 How to Update Oracle XE admin 2018.04.25 138
31 COUNT admin 2016.04.28 145
30 Outer Join with Oracle SQL admin 2016.04.29 147
29 Field Showing admin 2016.04.01 148
28 CREATE (INSERT) PROCESS admin 2016.04.28 150
» NVL admin 2016.05.19 151
26 PHONE NUMBER admin 2016.04.28 152
25 MAX admin 2016.04.28 154
24 DELETE PROCESS admin 2016.04.28 157
23 INSERT PROCESS admin 2016.04.28 159
22 SQL SELECT DISTINCT Statement admin 2016.04.29 160