NVL and COALESCE functions basic differences in DB2

The NVL function returns the first argument that is not null.

==>NVL(expression1, expression2)

The arguments are evaluated in the order in which they are specified, and the result of the function is the first argument that is not null. The result can be null only if all the arguments can be null, and the result is null only if all the arguments are null.

This SQL will return the names of all departments, along with the manager number. If there is no manager for the department, a value of “ABSENT” is displayed.

SELECT DEPTNO, DEPTNAME, NVL(MGRNO, ‘ABSENT’) AS MGRNO, ADMRDEPT FROM DEPARTMENT

Read more at: DB2- Use of ‘COALESCE’ Function (1 of 2)

DB2- Use of ‘COALESCE’ Function (2 of 2)

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.