Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2007
    Posts
    7

    Unanswered: abort insertion on statement level

    Hi

    Is there a way use trigger to prevent insertion of particular row?
    Code:
    CREATE TRIGGER stop_insert BEFORE INSERT ON T
    FOR EACH ROW
    BEGIN
      IF (...) THEN
          ??????
      END IF;
    END;
    thanks

  2. #2
    Join Date
    Dec 2003
    Posts
    1,074
    Code:
    CREATE TRIGGER stop_insert BEFORE INSERT ON T
    FOR EACH ROW
    BEGIN
      IF (...) THEN
          RAISE_APPLICATION_ERROR(-20500,'NOT ADDING RECORD');
      END IF;
    END;
    Your calling program would need to handle this situation in an Exception Handler, if it's supposed to continue in light of the error.

    --=cf

  3. #3
    Join Date
    Oct 2007
    Posts
    7
    oh...
    it's actually that easy
    and i keep thinking there must have been a command to do that


    thanks for the solution

  4. #4
    Join Date
    Mar 2007
    Posts
    623
    If your condition is simple (just expression on table columns), you may use a CHECK constraint.
    Also you may be interested in reading Data integrity chapter in the Concepts manual.

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    This could also be done with an instead of trigger, then the code could actually decide on the insertion. I don't think that this is a good idea, the application logic should be in the application, but it is another option.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  6. #6
    Join Date
    Oct 2007
    Posts
    7

    oops

    The problem is i cannot change the source code of the program calling it
    is there a way for oracle to handle the error?
    Last edited by xusword; 12-13-07 at 11:30.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •