today:
292
yesterday:
667
Total:
1,015,162

SQL NVL

admin 2016.05.19 15:08 Views : 159

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
66 Column Data 일괄 추가 admin 2023.11.24 167
65 SQL SELECT DISTINCT Statement admin 2016.04.29 169
64 Delete Message - Are you sure you want to delete this object? admin 2016.04.28 171
63 JAVA for delete admin 2016.04.28 172
62 UPDATE PROCESS admin 2016.04.28 174
61 DELETE PROCESS admin 2016.04.28 176
60 TAP ( Main & Sub ) / Button 의 Switch admin 2016.04.28 176
59 CREATING A TABLE / SEQUENCE / TRIGGER admin 2016.04.28 177
58 EXPORT & IMPORT admin 2016.05.01 180
57 Using SQL*Plus to Unlock and Change Passwords admin 2023.06.04 186
56 CREATE TABLESPACE admin 2016.04.28 187
55 Captcha Test file admin 2016.04.18 188
54 Apex setup procedure admin 2016.04.28 190
53 TABLE PRINT admin 2018.06.18 201
52 How to convert DATE to NUMBER admin 2018.05.27 206
51 Name Show admin 2016.04.28 212
50 MISSIONARY_SUB admin 2018.06.25 213
49 All Data DELETE from Table admin 2018.05.10 217
48 IF/ELSE ... CASE WHEN admin 2018.06.25 218
47 use a validation function for an element in apex 5.0 admin 2018.05.19 219