PL/SQL NVL

The NVL function replace a null expression with other expression.

NVL syntax

NVL (expression_1 , expression_2)

NVL example

 
select NVL(null, 1) from dual;

Result: 1


select NVL(null, 'my expression') from dual;

Result: 'my expression'

NVL example

STUDENT_ID FIRST_NAME LAST_NAME CITY ADDRESS
1 Daniel SCOTT New York
2 Anthony SIMMONS Chicago
3 Sophia THOMPSON Los Angeles
select s.STUDENT_ID, s.FIRST_NAME, s.LAST_NAME, 
s.CITY, NVL(s.ADDRESS, s.CITY) AS STUDENT_ADDRESS
from students s;
STUDENT_ID FIRST_NAME LAST_NAME CITY STUDENT_ADDRESS
1 Daniel SCOTT New York New York
2 Anthony SIMMONS Chicago Chicago
3 Sophia THOMPSON Los Angeles Los Angeles