title: How to select into a variable in PL/SQL when the result might be null?
body: <p>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.</p>
  
  <p>Currently, I can't do a <code>select into</code> a variable directly, since if the query returns nothing, the PL/SQL would complain variable not getting set. I can only run the query twice, with the first one do the count and if the count is zero, set the variable to null, and if the count is 1, select into the variable.</p>
  
  <p>So the code would be like:</p>
  
  <pre class="lang-sql prettyprint-override"><code>v_column my_table.column%TYPE;
  v_counter number;
  select count(column) into v_counter from my_table where ...;
  if (v_counter = 0) then
      v_column := null;
  elsif (v_counter = 1) then
      select column into v_column from my_table where ...;
  end if;
  </code></pre>
  
  <p>thanks.</p>
  
  <p>Update:
  The reason I didn't use exception is I still have some following logic after assigning the <code>v_column</code>, and I have to use <code>goto</code> in the exception section to jump back to the following code. I'm kind of hesitate of <code>goto</code> lines.</p>