Oracle: Get a query to always return exactly one row, even when there's no data to be found

前端 未结 6 1668
余生分开走
余生分开走 2021-01-18 01:17

I have a query like this:

   select data_name
   into v_name
   from data_table
   where data_table.type = v_t_id

Normally, this query shou

6条回答
  •  执笔经年
    2021-01-18 02:03

     select coalesce(data_table.data_name, d.data_name) data_name
       into v_name
       from 
       (SELECT 'UNKNOWN ' as data_name FROM DUAL)  d
       LEFT JOIN data_table
       ON data_table.type = v_t_id
              or a.data_table.data_name is null
    

提交回复
热议问题