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

后端 未结 8 720
广开言路
广开言路 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 14:44

    What about using MAX? That way if no data is found the variable is set to NULL, otherwise the maximum value.
    Since you expect either 0 or 1 value, MAX should be OK to use.

    v_column my_table.column%TYPE;
    select MAX(column) into v_column from my_table where ...;
    

提交回复
热议问题