• Sharebar

NVL function is used to substitute a value when a null value is encountered.This is useful in PL/SQL programming where we can supply default values when there is a chance of getting null at run time or to provide useful logging messages.

Example is given below.

SQL> set serveroutput on;
SQL> -- Created on 12/1/2008 by PLSQLTech Tips
SQL> declare
-- Local variables here
myStr varchar2(100);
begin
--Initialize the String
myStr := 'This is my string';
dbms_output.put_line(nvl(myStr,'This is to replace if string is null'));
--Now set the String to null;
myStr := null;
dbms_output.put_line(nvl(myStr,'This is to replace if string is null'));
end;
/

This is my string
This is to replace if string is null
PL/SQL procedure successfully completed.
SQL>

Technorati Tags:
, , ,

 
SEO Powered by Platinum SEO from Techblissonline