Thursday, February 5, 2015

Oracle: return a row even if select returns no rows

SELECT nvl(data_name, 'nothing') FROM (  
    SELECT data_name
    FROM data_table
    WHERE data_table.type = v_t_id

    UNION ALL

    SELECT NULL AS data_name
    FROM dual
  ) WHERE data_name is not null or ROWNUM = 1;