title: PL/SQL Oracle Error Handling
body: <p>I've created a trigger that only allows a user to have 10 current placed orders. So now when the customer tries to placed order number 11 the oracle database throws back a error. Well 3 errors. </p>
  
  <blockquote>
    <p>ORA-20000: You currently have 10 or more orders processing.</p>
    
    <p>ORA-06512: at "C3283535.TRG_ORDER_LIMIT", line 12</p>
    
    <p>ORA-04088: error during execution of trigger
    'C3283535.TRG_ORDER_LIMIT'</p>
  </blockquote>
  
  <p>The top error is one I've created using:</p>
  
  <blockquote>
    <p>raise_application_error(-20000, 'You currently have 10 or more orders
    processing.');</p>
  </blockquote>
  
  <p>I just wondered after search and trying many ways how to change the error messages for the other two errors or even not show them all together to the user?</p>
  
  <p>Here is the code I've used</p>
  
  <pre><code>    create or replace trigger trg_order_limit
      before insert on placed_order for each row  
      declare
      v_count number;
      begin
     -- Get current order count
     select count(order_id)
     into   v_count
     from   placed_order
     where  fk1_customer_id = :new.fk1_customer_id;
  
     -- Raise exception if there are too many
     if v_count &gt;= 10 then
     EXCEPTION
     WHEN OTHERS THEN
      raise_application_error(-20000, 'You currently have 10 or more orders  processing.');
     end if;
     end;
  </code></pre>
  
  <p>Thanks a lot
  Richard</p>