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.

Similar Messages

  • Transaction control statements in loop

    for i in p_time_duration_rspm_spm.first..p_time_duration_rspm_spm.last
    loop
    insert into green.solids_aaqm_namp(sample_nr,time_duration_rspm_spm,monometer_reading,
         avg_flow,total_sampling_period,vol_air_sampled,
                             filter_paper_nr,cup_nr)
                   values(p_sample_nr,p_time_duration_rspm_spm(i),
                        p_monometer_reading(i),p_avg_flow(i),
                        p_total_sampling_period(i),p_vol_air_sampled(i),
                        p_filter_paper_nr(i),p_cup_nr(i));
    end loop;
    hallo,
    i am facing a problem in the insert statement.There is a table(3*6).the fields in the table are
    of number datatype.if any character is entered in any of those field a error message as to be
    displayed.
    and if a character is entered into second row, then the readings in the first row is inserted
    in to the table and then a error message is prompted.i want to know whether can we use the transaction control statements
    within the loop to avoid inserting only one row.if so, how?...is there any other way to implement the same at the form level
    before going the database.

    Hello,
    FORALL i in p_time_duration_rspm_spm.first..p_time_duration_rspm_spm.last SAVE EXCEPTIONS
    insert into green.solids_aaqm_namp(sample_nr,time_duration_rspm_spm,monometer_reading,
    avg_flow,total_sampling_period,vol_air_sampled,
    filter_paper_nr,cup_nr)
    values(p_sample_nr,p_time_duration_rspm_spm(i),
    p_monometer_reading(i),p_avg_flow(i),
    p_total_sampling_period(i),p_vol_air_sampled(i),
    p_filter_paper_nr(i),p_cup_nr(i));
    end loop;
    If wants Errors then
    errors := SQL%BULK_EXCEPTIONS.COUNT;
    dbms_output.put_line('Number of DELETE statements that failed: ' || errors);
    FOR i IN 1..errors LOOP
    dbms_output.put_line('Error #' || i || ' occurred during '||
    'iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
    dbms_output.put_line('Error message is ' ||
    SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
    OR You can use as follows
    for i in p_time_duration_rspm_spm.first..p_time_duration_rspm_spm.last
    loop
    begin -- Newline Added
    insert into green.solids_aaqm_namp(sample_nr,time_duration_rspm_spm,monometer_reading,
    avg_flow,total_sampling_period,vol_air_sampled,
    filter_paper_nr,cup_nr)
    values(p_sample_nr,p_time_duration_rspm_spm(i),
    p_monometer_reading(i),p_avg_flow(i),
    p_total_sampling_period(i),p_vol_air_sampled(i),
    p_filter_paper_nr(i),p_cup_nr(i));
    EXCEPTION when OTHERS then -- Newline Added
    null; -- Newline Added
    end; -- Newline Added
    end loop;
    Bye
    Chitta

  • Business Transaction control based on equipment status

    I have created status profile  for equipment creation . One of the user status is "Created by User" . Now If the user status of the equipment is this , I  want  to disallow notification creation through iw21 on this equipment .
    Please explain in detail how to achieve this through transaction control in status profile (I have already tried object type "maintainence notif " etc in status profile ....but did not find transaction create notification which has to be forbidden .)..
    Also please explain how to view transaction code along with business transaction in transaction control screen ..(any alternate way ?)
    NPB

    hi
    kindly specify the object type as Equipment and check
    I am not sure, kindly mark the Create Log Notification as forbidden for the user status
    regards
    thyagarajan

  • Business Transaction Control is not Working for Equipment Status.

    Hi All,
    I have created a Status Profile for Equipment / Functional Location & assigned 5 Status under this Profile i.e. NEW, COM (Commissioning), INS(Inservice), CAM (Care & Maintenance) & DCM (De Commissioned). For Status DCM i have assigned Transaction control FORBIDDEN for "Enter PM processing data , Enter PM planing data & Create Meas. Doc."activities.
    It Means, whenever user creates Plant Maintenance Order OR Notification, Maintenance Plan OR Maintenance Item & Measurement Document for any Equipment / FL having this user status (DCM), system should not allow creation of above mentioned object.
    In my scenario, system is giving an standard error message " The business transaction cannot be carried out" during creation of "Plant Maintenance Order OR Notification, Maintenance Plan OR Maintenance Item".
    But i am able to create measurement document for equipment / FL having user status DCM with Transaction control Forbidden of Measurement document creation. No error message displayed by the system.
    Can anybody tell me why its happening? Why system is giving error during order & plan creation but not for Creation of measurement document ?
    If this is not posible in standard SAP, does any body knows about any OSS note so that we can implement the same to get an error message.
    Thanks in advance
    Arun

    Please ensure whether both projects have the same budget profile. Other than that you need to carefully investigate how the cost was posted onto both projects in the first place. Please note in case of procurements, budget is only checked at the commitments level (search the forum as this has been discussed before).
    In case this does not resolve your issue, revert back with the budget profile settings.
    Regards,
    Ammar

  • 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.

  • Is there a way to make state transitions/animations of a fl.control states - button for example ?

    Is there a way to make state transitions/animations of a fl.control states - button for example ?
    All I can do now is change the skin design and that's it, I can't animate between states like I can with Flash Builder skins. So is there a way to do that, any technique or I have to create a button component from scratch?
    Thanks!

    simplebuttons have upState etc properties you can use to assign movieclips to the 3 states.  you can use the currentFrame property of movieclps to (appear to) smoothly transition from one state to another.

  • 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.

  • Configuring toplink with EJB to transactional control "CMT"

    I try to use the EJB transaction CMT but I need to configure toplink to use a transactional control of my EJB container. some body knows how can i do this? and how can I configure the toplink to get JNDI datasource?
    Best Regards

    I dont think there is anything in Toplink you need to configure for CMT. All the transactional attributes are specified in the ejb-jar.xml file and I dont think you can edit this file using the Workbench or the Sessions Editor. With CMP the Workbench gives you an option to either overwrite this file or update but there is no way to "update" for transactional attributes. You can look at the examples for CMP (under folder advanced) that shows you how to use entity beans with Toplink in a CMP environment and you can look at the ejb-jar.xml file for more information.
    Configuring Toplink to get JNDI data source is easy-thats defined in the sessions.xml. Just open the sessions.xml using the sessions editor and click on login tab and then enter in the data source information.
    I try to use the EJB transaction CMT but I need to
    configure toplink to use a transactional control of
    my EJB container. some body knows how can i do this?
    and how can I configure the toplink to get JNDI
    datasource?
    Best Regards

  • 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

  • Control statement in internal tables

    hi experts,
    can any body will provide me the control statement of internal table.
                                                               thank you

    Hi,
    check this link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/content.htm
    Control Break Statements
    Control break statements are used to create statement blocks which process only specific table lines the LOOP – ENDLOOP block.
    You open such a statement block with the control level statement AT and close it with the control level statement ENDAT. The syntax is as follows:
    Table should be sorted when you use control-break statements
    You can break the sequential access of internal tables by using these statements.
    Syntax:
    At first.
    <Statement block>
    Endat.
    This is the first statement to get executed inside the loop (remember control break statements are applicable only inside the loop)
    So in this block you can write or process those statements which you want to get executed when the loop starts.
    At New carrid.
    Write:/ carrid.
    Endat.
    In this case whenever the new carrid is reached, carrid will be written.
    At End of carrid.
    Uline.
    Endat.
    In this case whenever the end of carrid is reached, a line will be drawn.
    At Last.
    Write:/ ‘Last Record is reached’.
    Endat.
    Processing of statements within this block is done when entire processing of entire internal table is over. Usually used to display grand totals.
    You can use either all or one of the above control break statements with in the loop for processing internal table.
    At end of carrid.
    Sum.
    Endat.
    In above case the statement SUM (applicable only within AT-ENDAT) will sum up all the numeric fields in internal table and result is stored in same internal table variable.
    Regards,
    Sruthi

  • How to handle transaction control--- in the dbms query or in JDBC? or BOTH?

    Hi all,
    we have a servlet application which do insert, update to a few sybase tables. so far we don't have any transaction management control in either store procedure or in JDBC call. i like to know where should we enforce this control logic? in both place or either one is enough?
    thanks!!

    according to your answer, is it safe to say that we
    should NOT
    handle transaction control in both query and JDBC
    call? i am on the side of JDBC
    program control. However our manager feels that if we
    handle it in two place, we could be more error-proof.
    i don't know how to convince him that only one place
    could make it work. Double your rollbacks double your fun! Odd that a manager is getting involved at this level...
    Providing transaction control at both places, as a rule makes absolutely no sense at all (to me). I actually believe that this would be far more error-prone (not error-proof). It's really a logistics issue. When you are working on the Java code, you won't have the stored procedure(s) code right there. While you may design it masterfully at first, as maintenance occurs, the mastery can easily be lost as assumptions are made on when and where commit or rollback processing is going to take place. The end result would be a system that could easily corrupt the logical integrity of the database.
    If you have to make a decision up front, and you believe performance will ultimately be a concern, then your decision should be to handle transaction management within the stored procedure(s). However, this decision will make the stored procedures far more complex than what the DBA or application staff is familiar with. You would also have to take some care to release resources as appropriate within the Java code.
    If you decide to manage transactions within JDBC, it is possible that you will have to move a portion of transaction managment to one or two of the stored procedures. This would be a 'fix' for a poorly performing functionality, and you would simply take care to limit this as much as possible.
    I wish I could guide you specifically, but I'm working at 20,000 feet related to your specific application needs.

  • Control statements

    When using control statements like AT FIRST...ENDAT.AT NEW (field).... ENDAT.
    Is it necessary to define the field (thru which we r going to group the records) as a first field in internal table?

    Hi,
         Control break statements are used to stop the control at a particular point.
    1. AT NEW f.
    2. AT END OF f.
    3. AT FIRST.
    4. AT LAST.
    Effect
    In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.
    You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.
    The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .
    At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:
    All default key fields (on the right) are filled with "*" after the current control level key.
    All other fields (on the right) are set to their initial values after the current control level key.
    Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).
    At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored
    use control break on any fields
    chk this sample program
    REPORT YCHATEST LINE-SIZE 350.
    TABLES MARA.
    DATA : BEGIN OF ITAB OCCURS 0,
             MATNR LIKE MARA-MATNR,
             AMOUNT TYPE P DECIMALS 2,
           END OF ITAB.
    ITAB-MATNR = '12345'.
    ITAB-AMOUNT = '100.20'.
    APPEND ITAB.
    CLEAR ITAB.
    ITAB-MATNR = '12345'.
    ITAB-AMOUNT = '100.20'.
    APPEND ITAB.
    CLEAR ITAB.
    ITAB-MATNR = '3456'.
    ITAB-AMOUNT = '100.20'.
    APPEND ITAB.
    CLEAR ITAB.
    sort itab by matnr amount.
    LOOP AT ITAB.
      AT END OF AMOUNT. 
        WRITE : / ITAB-MATNR , ITAB-AMOUNT.
      ENDAT.
    ENDLOOP.
    Regards

  • External transaction control and ability to find new registered objects

    Hello, We are using Toplink with external transaction control and have a process inserting a complex hierarchy of objects. During the process we either do a registerObject or deepmergeClone depending on if the instance is already in the db. With external transaction control the registerObject does not actually do the commit to db until the global transaction (Container) issues the commit. Unfortunately we end up doing creating multiple instances of same objects ( because the assumption that registerObject would have written the row to the db ) with the same keys and when the container issues the commit we end up with duplicate key violation. Is there a way to find out if an object with a particular key is already registered?

    This sounds like the kind of question that can only be answered with a whiteboard and a good review of your architecture.
    In general, there should be no problem registering objects multiple times. I.e.,
    x = some object
    x1 = uow.registerObject(x);
    Then x1==uow.registerObject(x), and x1==uow.registerObject(x1), etc. When you register an object with the UOW, based on PK it'll always return that same one.
    Do you have multiple units of work on the go? (that may explain this behavior).
    In any case, I think the real problem here is that you're somehow registering objects that are no longer cached. I.e., some object is serialized or rebuilt and then registered after it's gone from the cache. By default, TopLink determines if an object is new or existing (to determine INSERT vs UPDATE) by hitting the cache. You can change this default behavior in the Mapping Workbench, open the advanced property for "Identity" and change existence checking to "check database". Although, this can be a slow and tedious process to have to keep hitting the DB.
    A little trick I use sometimes is to take advantage of the "readObject" API that will read the object from the databaes if it's not already in cache, and just return it from cache if it is in cache. Check out the UOW primer at http://otn.oracle.com/products/ias/toplink/index.html for more info, but the jist is that I would do this if I were you:
    x = some object that you're not sure is cached and you want to register in UOW;
    x' = uow.readObject(x);
    IF the object was in cache, you'd get back a working copy, nice and fast. IF it's not in cache, you hit the database, it goes in cache, and you get your working copy. Now you don't have to change the existence checking option which could slow everything down.
    - Don

  • Usage of Transaction Control Extension

    Hi there,
    is the PA Transaction Control Extension (PATCX) only good for EXTENDING Transaction Controls,
    or can it also be used to REPLACE Default Transaction Controls?
    Regards
    Nils

    Hi,
    Transaction types are used in several components in SAP, e.g. in CS
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/d7/07542843b911d189ee0000e81ddfac/frameset.htm
    Since, it's a more 'what is it?' question, you can esaily find the answer by searching 'Transaction type' on hep.sap.com.
    Regards,
    Eli

  • Transaction Control Error

    Hi,
    i am getting "Transaction Control Error" in newly created Client while executing any tcode. can you please give the solution for this.
    venkat

    Hi,
    i copied from 000 client to new client. it was successfully completed. After that if execute mm01 or mm02 transactions this type error i am getting. Can you please give the solution..
    venkat

Maybe you are looking for