How to select into a variable in PL/SQL when the result might be null?

后端 未结 8 750
广开言路
广开言路 2020-12-07 14:08

Is there a way in to just run a query once to select into a variable, considering that the query might return nothing, then in that case the variable should be null.

8条回答
  •  广开言路
    2020-12-07 15:04

    COALESCE will always return the first non-null result. By doing this, you will get the count that you want or 0:

    select coalesce(count(column) ,0) into v_counter from my_table where ...;
    

提交回复
热议问题