Need Help with Database Trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gol
    New Member
    • Apr 2007
    • 1

    Need Help with Database Trigger

    Here is two tables: -

    Table A cols
    Message
    location
    city

    Table B cols
    Message
    location
    city

    I want to create a trigger, so that when any matching message column "HELLO" comes to table A, it gets to table B and get deleted from table A.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    please specify clearly

    which record u want to insert to table B
    (old or new)
    which record u want to delete from table A
    (old or new)

    and do u want to matching a particular word or what

    only then i can send u the code if u want

    Comment

    • wel
      New Member
      • Apr 2007
      • 5

      #3
      try this ... hope that will help
      we assume :
      - Tables and trigger are in scott's schema
      - Table A col Message
      - Table B col Message
      - The trigger is named TRIG_HELLO , will fire BEFORE INSERT on table A and when message is 'HELLO'

      CREATE OR REPLACE TRIGGER "SCOTT".TRIG_HE LLO
      BEFORE INSERT ON "SCOTT"."A"
      REFERENCING OLD AS OLD NEW AS NEW
      FOR EACH ROW
      WHEN (NEW.MESSAGE='HE LLO')
      BEGIN
      delete from "SCOTT"."A" where message='HELLO' ;
      insert into "SCOTT"."B" values ('HELLO');
      commit;
      END;

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Dear wel

        AS per the rule commands like COMMIT,ROLLBACK n SAVEPOINT can't be specified in a trigger body.

        Please don't post such things in the forum which u r not sure yourself.

        Comment

        Working...