Pages

How to use PL/SQL NVL?

NVL function is used to handle NULL values in a column.

NVL(columnName, valueIfColumnValueIsNotNull)

Example: Get student list with studentName, examGrade (if it is null put 50 instead)

SELECT studentName, NVL(examGrade, 50) FROM studentGrades


Note: An other way without NVL is to use CASE:


SELECT CASE WHEN examGrade IS NULL THEN 50 ELSE examGrade END FROM studentGrades

No comments:

Post a Comment