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

前端 未结 6 1721
余生分开走
余生分开走 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 01:48

    If you always expect zero or one row then you can use a group function i.e.:

    select dump(max(dummy)) from dual
    where dummy = 'Not Found'
    

    You will always get at least one row and a value of NULL in the case where the record is not found.

提交回复
热议问题