today:
434
yesterday:
667
Total:
1,015,304

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
41 ACTION admin 2019.01.11 6467
40 GP PRINT admin 2018.05.31 929
39 INSTR admin 2016.05.19 794
38 SELECT last_name FROM admin 2018.12.12 758
37 TREE admin 2016.05.18 731
36 CREATE TABLE admin 2018.09.25 482
35 SQL admin 2016.07.15 404
34 DATE Compare admin 2018.05.22 378
33 SUBSTR admin 2016.05.26 280
32 FOR LOOP admin 2016.05.20 278
31 ROWNUM admin 2016.05.19 246
30 Group by, Order by (두개의 Table을 활용한 Sub Total / 최고값 ) admin 2016.05.06 242
29 VERY IMPORTANT admin 2018.06.26 239
28 CREATE VIEW admin 2016.05.13 233
27 Report by Order / Product / Order and Product / By Order & Non Order admin 2016.04.29 230
26 MISSIONARY_SUB admin 2018.06.25 213
25 Name Show admin 2016.04.28 212
24 How to convert DATE to NUMBER admin 2018.05.27 206
23 TABLE PRINT admin 2018.06.18 201
22 CREATING A TABLE / SEQUENCE / TRIGGER admin 2016.04.28 177