Wednesday, September 18, 2013

How to return a default value if lookup fails on a table

given this table:

  CREATE TABLE "ACME_ERRORCODES" 
   ( "ERRORCODE" VARCHAR2(100 BYTE), 
 "ISRETRIABLE" NUMBER, 
 "ISCUSTOM" NUMBER
   ) ;



if you want to return a default value 0 for ISRETRIABLE in case the ERRORCODE is missing in the table, you can do:

select NVL ( 
   (select ISRETRIABLE from ACME_ERRORCODES where errorcode = 'SOME_MISSING_ERROR_CODE' ), 
    '0') 
from dual;




No comments: