How to access new value Statement Level Trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyanendar
    New Member
    • Jun 2007
    • 90

    How to access new value Statement Level Trigger

    Hi All,
    I want to access new value after upadate in statement level trigger.
    But in my query I am getting old values.
    Here is the Trigger Code:

    CREATE OR REPLACE TRIGGER TEST_TRIGGER
    AFTER UPDATE OF col3 on table_gyan
    DECLARE
    PRAGMA AUTONOMOUS_TRAN SACTION;
    v_count NUMBER:=0;
    v_temp_count NUMBER:=0;
    BEGIN
    SELECT Count(1) into v_count from table_gyan where col3='Y';
    If v_count>0 THEN
    SELECT COUNT(1) INTO v_temp_count from TRIGGER_TABLE;
    if v_temp_count>0 THEN
    UPDATE TRIGGER_TABLE SET ACTION='START';
    COMMIT;
    else
    insert into TRIGGER_TABLE(A CTION) values('START') ;
    commit;
    end if;
    END IF;
    END;

    .


    Now when ever I am executing this query
    update table_gyan set col3='Y'
    where col1='3'
    and col2='100'
    Its not doing anything with TRIGGER_TABLE.


    Please help me how to do it.

    Regards,
    Gyanendar
  • Pilgrim333
    New Member
    • Oct 2008
    • 127

    #2
    Are you sure any records are updated?

    Pilgrim.

    Comment

    • gyanendar
      New Member
      • Jun 2007
      • 90

      #3
      Originally posted by Pilgrim333
      Are you sure any records are updated?

      Pilgrim.
      In the table records are getting updated but trigger is still taking Old value.

      Comment

      • Pilgrim333
        New Member
        • Oct 2008
        • 127

        #4
        Ok,

        So now you have values in the table where col3 has the value 'Y' Try to update col3 now, and see if the trigger_table is updated.

        Pilgrim.

        Comment

        • gyanendar
          New Member
          • Jun 2007
          • 90

          #5
          Originally posted by Pilgrim333
          Ok,

          So now you have values in the table where col3 has the value 'Y' Try to update col3 now, and see if the trigger_table is updated.

          Pilgrim.

          No ,its not updating trigger_table values.
          If before updation table contains 'Y' than its working .

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            try using this code:

            [code=oracle]

            CREATE OR REPLACE TRIGGER TEST_TRIGGER
            AFTER UPDATE OF col3 on table_gyan
            DECLARE
            PRAGMA AUTONOMOUS_TRAN SACTION;
            v_count NUMBER:=0;
            v_temp_count NUMBER:=0;
            BEGIN
            SELECT Count(1) into v_count from table_gyan where col3=:new.col3;
            If v_count>0 THEN
            SELECT COUNT(1) INTO v_temp_count from TRIGGER_TABLE;
            if v_temp_count>0 THEN
            UPDATE TRIGGER_TABLE SET ACTION='START';
            COMMIT;
            else
            insert into TRIGGER_TABLE(A CTION) values('START') ;
            commit;
            end if;
            END IF;
            END;
            [/code]

            Comment

            • Pilgrim333
              New Member
              • Oct 2008
              • 127

              #7
              As this is a statement level trigger and firest once every statement, the individual values are not available in the trigger.

              But the post of amitpatel66 makes us think, make it a row level trigger and use the code amitpatel66 posted and see if the trigger_table table gets updated.

              Pilgrim.

              Comment

              • amitpatel66
                Recognized Expert Top Contributor
                • Mar 2007
                • 2358

                #8
                Yes this is for row level trigger.

                @OP, are you looking at Row level trigger updates or statment level? Please confirm?

                Comment

                • gyanendar
                  New Member
                  • Jun 2007
                  • 90

                  #9
                  Originally posted by amitpatel66
                  Yes this is for row level trigger.

                  @OP, are you looking at Row level trigger updates or statment level? Please confirm?
                  Yes,
                  Finally I made it row level trigger and every thing worked fine.

                  But,if 100 rows of table get updated than ,tigger will get fired for all the 100 rows and does the same work.To avoid this problem ,I was thinking for statement level trigger.

                  Guy's can we have statement level trigger for this work.

                  Regards,
                  Gyanendar

                  Comment

                  • Pilgrim333
                    New Member
                    • Oct 2008
                    • 127

                    #10
                    So, the same code works for row level statement, but doesn't work for the statement level trigger?

                    Pilgrim.

                    Comment

                    • amitpatel66
                      Recognized Expert Top Contributor
                      • Mar 2007
                      • 2358

                      #11
                      Originally posted by gyanendar
                      Yes,
                      Finally I made it row level trigger and every thing worked fine.

                      But,if 100 rows of table get updated than ,tigger will get fired for all the 100 rows and does the same work.To avoid this problem ,I was thinking for statement level trigger.

                      Guy's can we have statement level trigger for this work.

                      Regards,
                      Gyanendar
                      No you cannot. If you want it to work for all the records then you should have row level trigger

                      Comment

                      Working...