Commit a statement in  trigger

i have a trigger on a table like
create or replace trig_1
after insert
ON t1
referencing new as new old as old
for each row
begin
INSERT INTO t2 VALUES (:new.abd);
commit;
end;
this is working fine when i insert records in the main table with out commit in trigger .But when i place commit in trigger the insert statement fails showing commit exists on the trigger.
but i need to commit every row as soon as it is inserted

> Can you give some more information about the material, manufacturing and the like?
Quality craftsmanship goes into creating a finely balanced round pipe made of the highest grade of lead.
> Is it possible to get it colored (are there spring-time colors available)?
No!! <horrified expression>
It needs to be in harmony with the universe.. and thus is in the only perfect colour suited for a lead pipe. Gray.
> Is there any maintenance needed?
Yes, Cleaning the blood and miscellaneous "bits" from it. May I suggest our lead pipe cleaning kit for a mere $29.99?
> Are you delivering in non-EU countries?
As long as you pay in good old fashioned US dollars or Euros, it is not a problem.
> Will this lead pipe do any harm to the owner?
Only if you neglect the warning that lead pipes should only be used for situations that demand the dedicated, focussed and lovingly application of sheer bloody mindless violence... using the lead pipe of course.
> Is there a discount if you have more than 500 posts in this forum ;-)
ROFL!
:-)

Similar Messages

  • How to assign value in Statement level trigger?

    The below is my package body with trigger code..
    CREATE OR REPLACE PACKAGE BODY trigger_api AS
    TYPE t_change_rec IS RECORD (
    id tab1.id%TYPE,
    action tab1_audit.action%TYPE
    TYPE t_change_tab IS TABLE OF t_change_rec;
    g_change_tab t_change_tab := t_change_tab();
    PROCEDURE tab1_row_change (p_id IN tab1.id%TYPE,
    p_action IN VARCHAR2) IS
    BEGIN
    g_change_tab.extend;
    g_change_tab(g_change_tab.last).id := p_id;
    g_change_tab(g_change_tab.last).action := p_action;
    END tab1_row_change;
    PROCEDURE tab1_statement_change IS
    l_count NUMBER(10);
    BEGIN
    -- FOR i IN g_change_tab.first .. g_change_tab.last LOOP
    SELECT COUNT(*)
    INTO l_count
    FROM tab1;
    delete from tab1_audit where id=p_id;
    else
    dbms_output.put_line('Inside Else'||l_count);
    end if;
    -- END LOOP;
    -- g_change_tab.delete;
    END tab1_statement_change;
    END trigger_api;
    Trigger
    CREATE OR REPLACE TRIGGER tab1_asiu_trg
    -- AFTER INSERT OR UPDATE ON tab1
    AFTER DELETE ON tab1
    BEGIN
    trigger_api.tab1_statement_change;
    END;
    Calling Trgger
    Delete from tab1 where id='100';
    In the above package body which contains delete query, in that query i have to pass the value '100' i,e what are values i am giving in the (Delete from tab1 where id='100';) query.
    It shows error p_id Invalid Identifier..
    Thanks

    This wouldn't be related to your other threads would it by any chance?
    Re: How to call or not call a Trigger in same table based on condition?
    Re: Is it possible to use SELECT statement in TRIGGER?
    Can't you just stick to one thread to deal with your issue rather than asking it several times in different ways?
    You'll just cause confusion and frustrate people who are trying to help.

  • Statement level trigger!!!!

    Hi Gurus,
    I have an issue here. I am inserting multiple rows in a table say A. so I wrote an after insert trigger for each row referencing new as new and old as old on table A. This trigger when fired inserts rows in table B.
    These rows are selected from say table C by using the :new.column (one of the coulmns that are about to be inserted in tableA) of table A as parameter and then inserted into table B. But I want that trigger to fire only once though I am inserting multiple rows.
    For this purpose I took out the "for each row and referencing new as new and old as old statements" to make it statement level trigger but in this case I am unable to use the :new.column of table A as parameters. Can anyone please suggest how to read the rows in statement level trigger that are being inserted in table A and pass them as parameters to select the values from table C and again insert them in table B. I know it is kinda confusing. Any suggestions...... Thanks in advance!!!!!

    Hi warren,
    Thnx for ur response. here is the code
    CREATE OR REPLACE TRIGGER ALPHA_AIR
    AFTER INSERT
    ON ALPHA
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    l_source varchar2(10);
    l_amount number;
    l_comments varchar2(50);
    BEGIN
         SELECT      b_source,
              b_amount,
              b_comments
         INTO     l_source,
              l_amount,
              l_comments
         FROM BETA
         WHERE beta_id=:new.alpha_id:
         INSERT INTO GAMMA
    ( g_source,
         g_amount,
         g_comments,
         date )
         VALUES (
              l_source,
              l_amount,
              l_comments,     
              sysdate);
    END;
    The trigger is on table ALPHA and it selects data from BETA using :new.alpha_id as parameter. But for multiple rows inserted in table ALPHA, multiple times rows are inserted in table GAMMA. So I made it statement level trigger but I cannot pass :new.alpha_id as parameter in the select statement. Is there any way to do this. Hope it makes sense.

  • Commit work statement creating problem in CALL TRANSACTION

    Hi Friends,
    we are facing a problem where we need to call a standard program from a  Zprogram.
    we have tried the following ways.
    1. Using SUBMIT statement , we are sending the parameters to the standard program, but when the standard program gives a  
        dump our program cannot process further records. we are calling the submit statment in a loop. As because the standard
        program is giving dump our program is not able to process the next record in the loop and this should not be the case.
        To avoid this we have used the second method.
    2. we used a CALL transaction, we have created a Tcode for the standard program and called this transaction in the calling
        program. We are passing the parameters for the  standard program via BDC table. this works fine even when  the standard
        program gives a dump but when ever the control   comes across a Commit work statement the the control comes back to our
       calling program with out executing the rest of the   statments after the commit.
    now our concern is even though there is an commit work statement , statements after the commit work should also get executed in call transaction. Is thee any way?
    Regards,
    Sravan

    Hi All,
    I got the solution
    DATA: ctu_parameters TYPE ctu_params.
    ctu_parameters-dismode = 'E'.
    ctu_parameters-updmode = 'A'.
    ctu_parameters-racommit = 'X'. "No abortion by COMMIT WORK
    CALL TRANSACTION USING itab_bdcdata OPTIONS FROM ctu_parameters.
    the above code will work even if there is an commit work . This might help some others.

  • Need help: Sending mail to internet address without commit work statement

    Dear Experts,
            I have a problem in sending mails from sap to internet address.Am using the function module
    SO_NEW_DOCUMENT_SEND_API1 and am passing parameters like,
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
         EXPORTING
              DOCUMENT_TYPE  = 'RAW'
              DOCUMENT_DATA  = DOC_CHNG
              PUT_IN_OUTBOX  = 'X'
         TABLES
              OBJECT_CONTENT = OBJCONT
              RECEIVERS      = RECLIST
         EXCEPTIONS
              TOO_MANY_RECEIVERS         = 1
              DOCUMENT_NOT_SENT          = 2
              OPERATION_NO_AUTHORIZATION = 4
              OTHERS                     = 99.
    submit rsconn01 with mode = 'INT'
                        with output = 'X'
                        and return.
    My problem here is,with the commit work statement after FM, the mail is triggering correctly.but if, am not using the commit work statement,at the very first time of execution mail is not triggering, and the second time of execution first mail is triggering like wise it is going.The status of the message is waiting in queue.
    i have refresh receiver's list also.I want to use this concept in badi.So anyone can pls help me,how to send a mail without commit work statement.
    Thanks in advance.

    There is a parameter Commit_Work pass it as 'X'
    <code>
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
    DOCUMENT_TYPE = 'RAW'
    DOCUMENT_DATA = DOC_CHNG
    PUT_IN_OUTBOX = 'X'
    commit_work = 'X'
    TABLES
    OBJECT_CONTENT = OBJCONT
    RECEIVERS = RECLIST
    EXCEPTIONS
    TOO_MANY_RECEIVERS = 1
    DOCUMENT_NOT_SENT = 2
    OPERATION_NO_AUTHORIZATION = 4
    OTHERS = 99.
    submit rsconn01 with mode = 'INT'
    with output = 'X'
    and return.
    </code>
    Edited by: Saravanan Ramasamy on Nov 11, 2009 1:31 PM

  • Question about call statement in trigger

    I faced a question in written exam.
    A CALL statement inside a trigger allow us to call
    a)package
    b)procedure
    c)function
    d)another trigger
    Can anyone give me answer with reason?
    I used CALL statement inside trigger but not allowing to use it. Might be earlier in oracle CALL statement we can use..its only a guess so I am asking in forum..
    plz guide me..
    rgds,
    pc

    You can use CALL in a trigger without resorting to EXECUTE IMMEDIATE
    SQL> create table t1 (
      2    col1 number
      3  );
    Table created.
    SQL> create procedure t1_proc
      2  as
      3  begin
      4    dbms_output.put_line( 'In T1_PROC' );
      5  end;
      6  /
    Procedure created.
    SQL> ed
    Wrote file afiedt.buf
      1  create trigger trg_t1
      2    before insert on t1
      3    for each row
      4* call t1_proc
      5  /
    Trigger created.
    SQL> set serveroutput on;
    SQL> insert into t1 values( 1 );
    In T1_PROC
    1 row created.I can't think of any reason that you'd actually intentionally structure your code this way in this day and age because it would be rather likely to cause confusion for whoever had to support this in the future. But it is valid syntax that probably made sense back in Oracle 5.
    Justin

  • FRM-40735: illegal restricted procedure COMMIT in POST-CHANGE trigger

    I am using forms6i. I have three text fields FL1 ,*FL2* , FL3 in a form. Cursor passes from FL1 to FL2 and FL2 to FL3. I want when cursor transfers from FL1 to FL2 the form should be saved(commit). On FL1 i put COMMIT; in post-change.
    But when I pressed Enter key on FL1 it gives following error message.
    FRM-40735: illegal restricted procedure COMMIT in POST-CHANGE trigger
    Can you help me doing this.

    Gul wrote:
    I am using forms6i. I have three text fields FL1 ,*FL2* , FL3 in a form. Cursor passes from FL1 to FL2 and FL2 to FL3. I want when cursor transfers from FL1 to FL2 the form should be saved(commit). On FL1 i put COMMIT; in post-change.
    But when I pressed Enter key on FL1 it gives following error message.
    FRM-40735: illegal restricted procedure COMMIT in POST-CHANGE trigger
    Can you help me doing this.You cannot use COMMIT_FORM in post-change trigger. Because post-change only accept UN-restricted procedure. and commit is not.
    try this
    /* Trigger KEY-NEXT-ITEM on every item and write sample code */
    commit_form;
    next_item;Hope this works..
    Hamid
    Mark correct/helpful to help others to get right answer(s).*

  • FRM-40737:illegal restricted procedure COMMIT in WHEN-VALID_RECORD trigger

    Hello,
    I added the following code in Custom.pll, Event procedure. When Internet Expenses responsibility is added to a user on the User form in System Administrator repsonsibility, his default account will be populated from costing. I received error, "FRM-40737:illegal restricted procedure COMMIT in WHEN-VALID_RECORD trigger",
    when enter Internet Expenses in the Responsibility field and tab. Even though the account was populated right, the responsibility is not able to save to the form.
    /* When the employee id given Internet Expense responsibility, create appropriate expense account for the employee from costing */
    if(event_name='WHEN-VALIDATE-RECORD') then
    if(form_name ='FNDSCAUS' and block_name ='USER_RESP') then
    p_responsibility_id := to_number(name_in('USER_RESP.RESPONSIBILITY_ID'));
    --p_responsibility_name := name_in('USER_RESP.RESPONSIBILITY_NAME');
    p_user_id := to_number(name_in('USER_RESP.USER_ID'));
    if (p_responsibility_id = 22918) then
    select employee_id
    into p_person_id
    from fnd_user
    where user_id = p_user_id;
    apps.cov_oie_pkg.update_emp_exp_act(p_person_id);
    commit;
    end if;
    end if;
    end if;
    Any suggestion will be highly appreciated!
    Yan

    You are calling 'COMMIT' after your custom package. You cannot use COMMIT in when-validate triggers. Did you try taking out COMMIT and save the record?

  • Is 'Commit Work' statement necessary?

    Is it mandatory to issue 'Commit Work' statement to terminate the program in SAP LUW? If not provided would the program go into infinite loop?

    ... just before the thread gets locked:
    There is no such thing as an implicit commit work. The implicit commit is a database commit, that means after every process interruption as i.e. processing of any screen and the end of program execution all database activities are committed, they can not be rolled back.
    The explicit ABAP statement COMMIT WORK will termiante the current LUW and, additionally start execution of all asynchronous database operations (Call function in update task), start all PERFORM ON COMMIT routines.
    Most BAPI calls need a subsequent COMMIT WORK, better issued by function Call BAPI_TRANSACTION_COMMIT.
    The documentation has more information. One major truth is: In 'simple' programs that do some INSERTS, UPDATES and MODYFYs on database tables, you do not need any COMMIT WORK. And if screen processing happens afterwards, you can not ROLL BACK.
    Regards,
    Clemens

  • How to count " How many times the ' commit work ' Statement is executed.

    Hi all sap Champions,
    One of the client requirement, That is
    How to count " How many times the ' commit work ' Statement is executed.
    It's urgent.
    Please can anybody help me for this.
    Thanks
    Basu

    hi,
    when report try like this.
    declare a variable as
    data: counter type i value 0.
    COMMIT.
    counter = counter + 1.
    write:/10 counter 'NO. OF TIMES COMMIT WORKED'.

  • Commit not allowed in Trigger  then how to store the values in table

    Hi,
    Database trigger not allowed to COMMIT in it (directly) or in procedure which is calling from the Trigger. it gives error.
    so my question is:-
    1)How Database internally store the INSERT AND UPDATE value in table which is written in procedure without COMMIT?
    2) Is it necessary to write COMMIT in procedure using PRAGAMA AUTONOMOUS TRANSACTION to store inserted or updated value in table?
    Thanks in advance.

    Hi,
    A trigger is designed to be a part of a transaction, not it's end.
    It is like following these steps (not really accurate, but should give an idea):
    1. programA issues INSERT statement on tableA
    2. 'control' goes over to the database
    3. constraint checks happen
    4. the associated triggers on tableA do their work (e.g. fetching a sequence value for a primary key)
    5. 'control' goes back to programA
    6. programA decides if a commit (no error occurred) or a rollback (error case) has to be issued.
    Did this help? Probably not, I'm not happy with what I wrote, but anyway... :)

  • How to Commit transaction even the trigger fails?

    Hi Everyone,
    I got a situation here, i have two tables and a trigger. A main table and a log table. Whenever  a change happens in the main transaction ,   a log details will be inserted into the log table.
    Am using sql server 2000 and "For insert,update,delete" in one trigger. 
    I am in need of commiting the original transaction even if the trigger fails. I mean the main table is so important for me, so all the transaction should commit in the main table no matter if some transactions details missed in the log table.
    I tried with
    begin try
    -- statement
    end try
    begin catch
    commit transaction
    end catch.
    But it doesnt works. My insert fails whenever the trigger fails. i want the transaction should continue even if the trigger fails...
    Pls suggest me how to do it.. Thanx for your help

    If the trigger action is optional, it should not be in a trigger. The idea of a trigger is that it is part of the statement, so if the trigger fails, the statement fails.
    As for what your alternatives are, it depends on which version on SQL Server you are using. You first say SQL 2000, but then you discuss TRY CATCH which was added in SQL 2005.
    What always works is to have a separate process that scans the main table for changes and the update the log. It can be difficult to identify the changes, though. It helps if you are on SQL 2008 where you can use Change Tracking.
    Another solution is to put a message on a Service Broker queue in the trigger, and then you have an activation procedure where you perform the operation with the log table. Of course, the SEND operation may fail, and you are back on square one. But it may
    be less likely that this fails than producing the log operation if this is complex and fragile.
    Also, a possibility is to add this statement to the trigger:
    SET XACT_ABORT OFF
    In this case, some errors in the trigger will not cause the statement to fail. More precisely, not errors that under normal circumstances terminates only the current statement, for instance PK violations, NOT NULL errors. There are still
    plenty of errors that always aborts the batch and rolls back the open transaction. For instance, conversion errors often rolls back the transaction. Note that SET XACT_ABORT only has effect in SQL 2005 or later.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Subquery in IF statement in trigger, without using foreign keys

    Hello,
    I'm investigating ways of writing a subquery in an IF statement, which is placed inside a trigger.
    I wanna write smth like IF (:new.jazz not in (select goldies from T where ... )) etc. I don't know whether the fact that the IF is in a trigger adds some additional restrictions. (Does it?)
    So far I found the solution described here: SubQuery Comparison in If Statement which I find a bit tacky, I could have the 'cooleststarinthegalaxy' instead of 1 and seems you need to do extra light, but still extra lifting.
    I also read about the possibility of using MERGE, which I'm currently researching.
    Is there any other way?
    Thanks
    Edited by: BluShadow on 14-Nov-2012 13:37
    fixed link
    Edite by me: the question is how (if possible) to do this without a foreign key.
    Edited by: questioningq12 on Nov 14, 2012 6:11 AM
    Edited by: questioningq12 on Nov 14, 2012 6:13 AM

    Hi,
    questioningq12 wrote:
    Say I have tables A(namea varchar(10)), B(nameb varchar(10)), and B contains tuples ('1stname','2ndname').
    I wrote a trigger before insertion, for each row, on table A. For a tuple t to be inserted, it should check whether t.namea is in the set of values nameb from B.
    E.g., INSERT INTO A VALUES('1stname') should work. But INSERT INTO A VALUES ('3rdname') should fail. You can use a foreign key constraint for that.
    If the tables already exist, and b.nameb is declared as UNIQUE (or PRIMARY KEY), then you can say:
    ALTER TABLE  a
        ADD CONSTRAINT     a_namea_fk
        FOREIGN KEY  (namea)
        REFERENCES b (nameb)
    ;If you had a situation where you really needed to query a table in PL/SQL, and you weren't sure if the query would find anything, you could put the query in its own BEGIN ... EXCEPTION block, and test for NO_DATA_FOUND.
    If you're just checking to see if a row exists or not, you can always write a query that is guaranteed to return exactly 1 row, like this:
    BEGIN
        SELECT  COUNT (*)
        INTO    x
        FROM    b
        WHERE   nameb = :NEW.namea
        AND         ROWNUM  = 1;
        IF x = 0
        THEN  
            ...        -- print msgs, raise exceptions etc
        END IF;
    END;Edited by: Frank Kulash on Nov 14, 2012 9:22 AM
    Added example

  • Confusion in Order of row and statement level trigger

    Hi can anyone tell me, if i create some trigger on table emp as in below order..
    BEFORE INSERT .. ROW LEVEL
    BEFORE INSERT .. STMNT LEVEL
    AFTER INSERT .. ROW LEVEL
    AFTER INSERT .. STMNT LEVEL
    than what will will be order of execution of trigers?
    How oracle will decide order?
    plz provide me some documents related to triggers execution order..thnx in advance..!

    PC wrote:
    Hi.. Got answer about order..but 1 strange point i m feeling that
    in case of, before insert.. stmnt level triger fire 1st then before insert.. row level.
    but in case of after insert.. row level trigger fireing 1st then after insert.. stmnt level ..
    can you explain this also..Why is it strange.
    You've got a statement you are executing.
    The first thing possible is that you are 'before' the statement.
    The next thing possible is that the statement executes for each row.
    Thus for each row, there is a point 'before' each row and a point 'after' each row.
    Once the statement has executed, you are 'after' the statement.
    So, it is only logical that the statement triggers surround the statement and the row triggers are within the statement, and of course 'before' comes before 'after'.

  • Transactional control statements in trigger

    Hi,
      Transaction Control statement, which cannot be executed within a trigger body??why...explain with reason
    its helpful me..

    Ishan wrote:
    "a way you can actually make it work" .... seriously?
    Yes, I was serious. Why? What's wrong with that? Technically speaking, won't it work?
    This is not a way to make it work, it's a way to break an application/process
    Well !!! All the cases?
    Here's  a scenario
    I want to audit a table where if any change done by the user has to be tracked in an audit table, irrespective whether the change has now been rolled back in the main table. I want to see what change was done? How would I do it? Going by your logic of breaking application/process, I should never use trigger as  AUTONOMOUS_TRANSACTION. Am I right? How would I achieve it now?
    Your auditing/tracing code should be in a separate procedure and that procedure should be autonomous, so that the requirement to write autonomous data for that purpose is kept isolated from the trigger code.  Consider this scenario instead.  You want to write audit/trace information from your triggers, so you make the trigger autonomous and put in your code to write the audit/trace information.  Later on, someone who hasn't a clue comes along and decides they need to do something else in that trigger (well why write a new trigger when one already exists?) and they get it to write some data in relation to the data being created by the trigger.  Now you suddenly have a transactionally unsafe application, where this 'child data' can still be written and committed even if there's a problem in the main transaction.  By isolating auding/tracing away to it's own autonomous procedure, you make it clear that it's only the auditing/tracing that should be autonomous and prevent any problems from occuring inside the trigger itself.
    That's more of a way to write bad code that is transactionally unsafe and demonstrates a lack of understanding of database transactional processing or how the rdbms on the server processes commits and could potentially lead to write contention in the writer processes, of which many would be spawned if the number of inserts (in this example) was high.
    The above comment is based on the assumption(which, I never stated) that in whatever scenario my code would be implemented, it would ALWAYS break the process. There are scenarios where this code could be required.
    Here's a link from Oracle Documentation, that uses an example of creating a trigger with AUTONOMOUS_TRANSACTION. If it is a so bad example which "demonstrates a lack of understanding of database transactional processing", why would Oracle even mention it in their documentation?
    http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/sqloperations.htm#BABDHGAB
    And the answer is because there is a way to do it and it could actually be required, even though it's rare.
    I just showed OP, that it's not allowed directly and if required, it can be done as there is a way to do it. When to do it and what could be the consequences was never the scope of the question.
    Yes, and there's ways to jump off cliffs and kill youself, but I wouldn't recommend demonstrating how to do that to people just because it's possible.
    Just because it's in the oracle documentation doesn't always mean it's best practice.  A lot of the documentation was written a long time ago and best practices have changed as well as further functionality added, and Oracle has been known to make mistakes in their documentation too.  However in this example, it's using it for auditing purposes, so the idea was almost there, but they still haven't met best practices of keeping the auditing isolated, so their example is not the best.

Maybe you are looking for

  • Successfully Intalled Oracle 11i E-Business Suite in windows platform !

    Dear All After struggling almost 15 days (documents searching from google, metalink etc...), successfully intalled more than 6 times in Window 2000, windows 2003, and Windows XP . Anyone wants to know the steps contact me directly, i will advice you

  • How to split data into tables based on the entries in a column?

    My problem is very similar to this thread: how to link data from one numbers sheet to another sheet, however I could get it to work the way described there. I have one big table for entering data (the first one). I would like to have a few other tabl

  • FCP Backup Project Questions

    Hi Everyone, Say I had several questions and was hoping another FCP user could answer them for me. I recently had a hard drive fail that housed all of the captured video for a project that was complete, but had not yet been exported out. A real bumme

  • Essbase Rules Files and OCI

    Hi All, I am using EPM 11.1.2.1. I want to use rules files and Sql interface to build outline and load data. Can anyone please provide / guide me with the steps to connect using ODBC and OCI ? I tried but it gives error Error: 1021001 Failed to Estab

  • 0Job_attr

    Hi There, I was trying to extract master data 0job_attr. when i scheduled the info package, i had a caller error, saying error occured in the source system. then i tried to check the same in rsa3, and i have a message, error occured during extraction