CREATE OR REPLACE FUNCTION NVL2 (val IN VARCHAR2 , ifnotnull IN VARCHAR2 , ifnull IN VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN CASE WHEN val IS NOT NULL THEN ifnotnull ELSE ifnull END; END; /
01 November 2010
A better alternative to NVL2 (29 October quiz) (1565)
The 29 October quiz tested your awareness of the NVL2 function (which works quite differently from NVL), and the fact that it is available only in SQL, not yet in the PL/SQL language. The quiz offered several options that served, in effect, as alternatives to NVL2, from within PL/SQL. Vitaliy wrote to suggest that I had missed a simpler and more elegant alternative: CASE. So just in case you would like to use it....