title: Appending BEGIN EXCEPTION lines into plsql file using sed
body: <p>I have a few sql files which contain thousands of INSERT statements. The problem when executing these scripts is that some of them violate the unique constraint.</p>
  
  <p>I originally did something like this:</p>
  
  <pre><code>BEGIN
      INSERT INTO .....;
      INSERT INTO .....;
      ...
  EXCEPTION 
      WHEN DUP_VAL_ON_INDEX THEN
         null;
  END;
  /
  EXIT;
  </code></pre>
  
  <p>However it seems the first instance where the exception occurs will cause the entire block to end, so the rest of the statements are not executed.</p>
  
  <p>Since the Oracle version I'm using is not 11, I can't use the nice CONTINUE command. So I am thinking of doing something like this for <strong>each</strong> INSERT INTO statement:</p>
  
  <pre><code>BEGIN
      INSERT INTO ....;
  EXCEPTION 
      WHEN DUP_VAL_ON_INDEX THEN
         null;
  END;
  /
  
  ...
  </code></pre>
  
  <p>How can I use sed to read each line in the sql file, scan for the words "INSERT INTO" and if that exists, then append the BEGIN and EXCEPTION lines in between the INSERT INTO line? The reason is, sometimes a line is just a comment and I don't want to append to that. </p>