×
☰ See All Chapters

Oracle NVL Function

Oracle NVL function is used to substitute a value when null value is encountered. This returns the substitution value if the source has null in it.

Oracle NVL Function Syntax

NVL (Source, Substitution_Value)

Source: an expression or a direct value or a value from a column of any type

Substitution_Value: Substitution value.

Oracle NVL Function Examples

Creating table for demonstrating NVL Function

CREATE TABLE CONVERSION_FUNCTIONS

(

  NUMERIC_VALUE  INTEGER,

  STRING         VARCHAR(10 ),

  DATE_VALUE     DATE

);

INSERT INTO CONVERSION_FUNCTIONS (NUMERIC_VALUE) VALUES (12091990);

INSERT INTO CONVERSION_FUNCTIONS (NUMERIC_VALUE, STRING) VALUES (01031991, 'CCC');

INSERT INTO CONVERSION_FUNCTIONS (NUMERIC_VALUE, STRING, DATE_VALUE) VALUES (11121990, 'DDD', to_date('1995-12-18','yyyy-mm-dd'));

Example 1

SELECT

   NUMERIC_VALUE,

   NVL

 

   (

      STRING,

      'ABCD'

   )

FROM

   CONVERSION_FUNCTIONS

oracle-nvl-funtion-0
 

Example 2

SELECT

   NVL

 

   (

      STRING,

      'ABCD'

   ),

   NVL

 

   (

      DATE_VALUE,

      to_date

      (

         '1990-01-01',

         'yyyy-mm-dd'

      )

   )

FROM

   CONVERSION_FUNCTIONS

oracle-nvl-funtion-1
 

All Chapters
Author