title: Exit execution when error occurs PL/SQL
body: <p>I would like to know, how can I exit the execution when an error occurs. In Microsoft SQL Server there is a <code>RETURN</code> clause, which does the work. But I would like to know similar functionality in Oracle. I am using Oracle Sql Developer. Here is the script I am using:</p>
  
  <p>First block throws error due to Unique Key Violation, even though it throws error the execution goes to next block and executes the insert statement. I want to end the execution or exit at first block of code itself.
  Please help me to write the code.</p>
  
  <p>First anonymous PL/SQL block:</p>
  
  <pre><code>set serveroutput on;
  
  BEGIN 
    insert into test values(1);
    insert into test values(1);
    COMMIT;  
  
    dbms_output.put_line('PRINT SOMETHING 1'); 
  
  EXCEPTION
     WHEN OTHERS THEN
       if sqlcode &lt;&gt; 0
       then
          dbms_output.put_line(SQLCODE || '  ' || SQLERRM);
          RAISE; 
       end if;
       return;
  END;
  / 
  </code></pre>
  
  <p>Second anonymous PL/SQL block:</p>
  
  <pre><code>set serveroutput on;
  
  BEGIN 
    insert into test values(6);
    COMMIT;  
  
    dbms_output.put_line('PRINT SOMETHING'); 
  
  EXCEPTION
     WHEN OTHERS THEN
       if sqlcode &lt;&gt; 0
       then
          dbms_output.put_line(SQLCODE || '  ' || SQLERRM);
          RAISE; 
       end if;
       return;
   END;
  / 
  </code></pre>