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

前端 未结 6 1720
余生分开走
余生分开走 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:54

    I would prefer to handle the exception. However, this would work as you specify:

    select min(data_name) data_name
    into v_name
    from data_table
    where data_table.type = v_t_id
    

    Note that this also "works" if the query returns more than 1 row - i.e. TOO_MANY_ROWS is not raised.

提交回复
热议问题