Skip to content
Advertisement

Replace blank value with a default value in SQL

i have the below query which return blank values for the column property_value :

select target_name,target_type,property_name,property_value
from oracle_properties
where target_name like 'DY01EPI%' and property_name like 'DataGuardStatus' 

output from sql developer:

enter image description here

How can i get a default value like ‘primary’ if the the row in Property_value is blank. I have tried using NVL(property_value,'Primary') and COALESCE(property_value,'Primary') which didnt give expected result.Please suggest.Thanks.

Advertisement

Answer

Presumably, the value is not NULL. You might use regular expressions for this:

select target_name, target_type, property_name,
       (case when regexp_like(property_value, '[a-zA-Z0-9]') then property_value
             else 'primary'
        end) as property_value
from oracle_properties
where target_name like 'DY01EPI%' and
      property_name like 'DataGuardStatus' 
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement