title: PL/SQL how to check if exists and return error code
body: <p>Disregard if using MERGE INTO is better in this case or not. I just wonder if I can check if the row exists or not. If not, then set the return code to 1 and return immediately. If yes, then continue to execute the rest of code and set return code to 0 in the end. Below code is not working as it always executes to the end. How should I fix it? </p>
  
  <pre><code>  BEGIN
  
      -- check 
      SELECT CASE
        WHEN NOT EXISTS (SELECT 1 FROM s WHERE s.col1 = 1 AND s.col2 = 2)
        THEN 1
      END
      INTO ret FROM dual;
  
      -- update
      UPDATE s
      SET s.col3 = 3
      WHERE s.col1 = 1 AND s.col2 = 2;
  
      COMMIT;
  
      SELECT 0 INTO ret FROM dual;
      RETURN ret;
  
    END foo;
  </code></pre>
  
  <p>What if I want be able to distinguish if it's <code>s.col1 = 1</code> not exist or <code>s.col2 = 2</code> not exist. And have 2 different return codes for them. How should I do in this case?</p>