autonomous transaction block of exception

Hi friends,

Can you tell me if it is possible to use an autonomous transaction block exception?

If so, how? Please provide me with a guide line

thnx

ROY wrote:
Hi friends,

Can you tell me if it is possible to use an autonomous transaction block exception?

If so, how? Please provide me with a guide line

You cannot use an autonomous transaction directly in the exception block:

SQL> ed
Wrote file afiedt.buf

  1  declare
  2    v_dummy number;
  3  begin
  4    select a into v_dummy from testtab where a = -1;
  5  exception
  6    when no_data_found then
  7      declare
  8        pragma autonomous_transaction;
  9      begin
 10        insert into testtab (a) values (-1);
 11      end;
 12      raise;
 13* end;
SQL> /
      pragma autonomous_transaction;
             *
ERROR at line 8:
ORA-06550: line 8, column 14:
PLS-00710: PRAGMA AUTONOMOUS_TRANSACTION cannot be specified here

but, if it is declared in a procedure you can call it the exceptional block...

SQL> ed
Wrote file afiedt.buf

  1  declare
  2    v_dummy number;
  3    procedure insertit is
  4      pragma autonomous_transaction;
  5    begin
  6      insert into testtab (a) values (-1);
  7      commit;
  8    end;
  9  begin
 10    select a into v_dummy from testtab where a = -1;
 11  exception
 12    when no_data_found then
 13      insertit;
 14      raise;
 15* end;
SQL> /
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 14

or

SQL> ed
Wrote file afiedt.buf

  1  declare
  2    v_dummy number;
  3  begin
  4    select a into v_dummy from testtab where a = -1;
  5  exception
  6    when no_data_found then
  7      declare
  8        procedure insertit is
  9          pragma autonomous_transaction;
 10        begin
 11          insert into testtab (a) values (-1);
 12          commit;
 13        end;
 14      begin
 15        insertit;
 16      end;
 17      raise;
 18* end;
SQL> /
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 17

Tags: Database

Similar Questions

  • Can ' transaction autonomous pragma ' called from exception block?

    CREATE OR REPLACE TRIGGER TRIG_EMP
    AFTER UPDATE
    ON EMP
    FOR EACH LINE

    DECLARE

    NUMBER OF THE CNT: = 0;

    BEGIN

    UPDATE EMP_bkp
    SET COMM = 999
    WHERE ENAME = 'SMITH ';.

    COMMIT; -It will generate the error that commit the cnt b use inside the trigger then wil code exception sommunications

    exception
    while others then
    declare
    PRAGMA AUTONOMOUS_TRANSACTION;
    Start
    commit;
    end;
    END;


    Why code gives error? cant I put PRAGMA AUTONOMOUS_TRANSACTION block of exception, even if I have the rolls in declare... begin... end of block.
    Could be considered to bear, but I m in delema why we cnt pragma 'use', in the exception block when an error themselves in code.as can call any proc, func via exception block then why don't we call pragma?

    A pragma shall apply to a set routine:
    -The anonymous PL/SQL blocks higher level (not nested)
    -Local, autonomous and packaged functions and procedures
    -A SQL object type methods
    -Database triggers

    But, even if you set a pragma autonomous_transaction in the exceptions, these commit will not commit the changes maded in the body of the trigger (because the idea of a stand-alone transaction, is independent).

    Perhaps (I'm not sure) you can try to trick Oracle write a function that do the validation.

    In any case, what you trying to do? There may be another way to achieve your goals

    I hope this helps.

    Kind regards
    Alfonso Vicente
    http / / www.logos.com.uy/el_blog_de_alfonso

  • ORA-06519: active autonomous transaction detected and restored

    Hello

    I have a trigger and stored procedure of the trigger call. This stored procedure contains instructions COMMIT. So I used PRAGMA AUTONOMOUS_TRANSACTION in my trigger. I created the trigger to fire after insertion in the table. When I try to insert the data, I get the error below.

    ORA-06519: active autonomous transaction detected and restored

    Can anyone clear or correct me.

    Thank you

    Before returning in a PL/SQL block, autonomous transactions started in the block must be met (to the either committed or rolled back at the back). If this is not the case, the active autonomous transaction implicitly rolls back and this error.

    Ensure that, prior to return from an autonomous PL/SQL block, autonomous, all active transactions are explicitly committed or canceled.

  • "An autonomous transaction sees all changes by hand transact.

    Hello
    I'm trying to reproduce designs "a stand-alone transaction sees all changes made by the main transaction" on:
    Oracle® Database Application Developer's Guide - Fundamentals
    10g Release 2 (10.2)
    Part Number B14251-01
    chapter 2 SQL Processing for Application Developers

    Paragraph : Autonomous Transactions
    I implemented a simple case...
    create table emp_ as select * from emp

    begin
      update emp_ set hiredate=hiredate+100 where empno=7934;
    end;

    create or replace trigger trg_emp_
    after insert or update on emp_
    for each row

    declare
        pragma autonomous_transaction;
        emp_var emp.hiredate%type;

      begin
        select hiredate
          into emp_var
          from emp_
        where empno=:new.empno;
        dbms_output.put_line('empno: '||:new.empno);
        dbms_output.put_line('old hiredate: '||:old.hiredate);
        dbms_output.put_line('new hiredate: '||:new.hiredate);
      end;
    Before any change...
    SQL> select empno,hiredate from emp_;

    EMPNO HIREDATE
    ----- -----------
    5498 21/4/1982
    5499 11/10/1981
    5411 10/10/1981
    5410 10/10/1982
    7369 17/12/1980
    7499 20/2/1981
    7521 22/2/1981
    7566 2/4/1981
    7654 28/9/1981
    7698 1/5/1981
    7782 9/6/1981
    7788 19/4/1987
    7839 17/11/1981
    7844 8/9/1981
    7876 23/5/1987
    7900 3/12/1981
    7902 3/12/1981
    7934 23/1/1982
    After the change...
    SQL> begin
      2    update emp_ set hiredate=hiredate+100 where empno=7934;
      3  end;
      4  /

    empno: 7934
    old hiredate: 23/01/82
    new hiredate: 03/05/82

    PL/SQL procedure successfully completed
    According to the doc select Oracle of the autonomous transaction should not see the change to column hiredate in table in the main transaction (in the anonymous block)...

    Matter what I've done wrong... ???

    Thank you
    SIM

    Simon:

    As Tubby has pointed out, your dbms_output orders do not display the selected value in the trigger. Your trigger based demonstration should look like:

    SQL> SELECT * FROM t;
    
            ID DT
    ---------- -----------
             1 05-SEP-2009
             2 17-JUL-2009
    
    SQL> CREATE TRIGGER t_ai
      2     AFTER INSERT OR UPDATE ON t
      3     FOR EACH ROW
      4  DECLARE
      5     PRAGMA AUTONOMOUS_TRANSACTION;
      6     l_dt t.dt%TYPE;
      7  BEGIN
      8     SELECT dt INTO l_dt
      9     FROM t
     10     WHERE id = :new.id;
     11     DBMS_OUTPUT.Put_Line ('ID: '||:new.id);
     12     DBMS_OUTPUT.Put_Line ('Old dt: '||:old.dt);
     13     DBMS_OUTPUT.Put_Line ('New dt: '||:new.dt);
     14     DBMS_OUTPUT.Put_Line ('Aut dt: '||l_dt);
     15  END;
     16  /
    
    Trigger created.
    
    SQL> UPDATE t SET dt = sysdate WHERE id = 2;
    ID: 2
    Old dt: 17-JUL-2009
    New dt: 25-OCT-2009
    Aut dt: 17-JUL-2009
    
    1 row updated.
    

    Thus, the transaction, select automomous doesn't see the modified value of dt.

    I know you are just trying to understand transactions automomous here and would never sometihg like that in the production of right? :-)

    Your trigger, as written, has some interesting side effects because of the automomous transaction. For example:

    SQL> INSERT INTO t VALUES(3, sysdate - 25);
    INSERT INTO t VALUES(3, sysdate - 25)
                *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "OPS$ORACLE.T_AI", line 5
    ORA-04088: error during execution of trigger 'OPS$ORACLE.T_AI'
    
    SQL> UPDATE t SET id = 3 where trunc(dt) = TO_DATE('05-Sep-2009', 'dd-mon-yyyy');
    UPDATE t SET id = 3 where trunc(dt) = TO_DATE('05-Sep-2009', 'dd-mon-yyyy')
           *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "OPS$ORACLE.T_AI", line 5
    ORA-04088: error during execution of trigger 'OPS$ORACLE.T_AI'
    

    John

  • The block 'add exception' is not active

    The block 'add exception' is not active in the section "I understand the risks" untrusted connection. I had to use IE to access my wireless router? Any suggestions?

    I am running Firefox under Win 8 17.0.1.

    Keith Brewer

    Hey keith, is this help article? : certificate contains the same serial number for another certificate

  • Engage in relaxation with an AUTONOMOUS transaction

    Hi all

    My question is on the trigger. say if we have a before insert trigger wrote on the employee table who agrees to pay his transaction with autonomous, so if our insert on employee statement fails, the trigger is executed as it is before the outbreak.

    Practically, I checked and found that it is not have triggered. Please clarify my understanding trigger a trigger.

    Thank you

    Vipin Kumar Rai

    It's just the way it is. If a fundamental data type is violated, it fires. If a constraint (as a non null) is violated, then he fired.

    I know that you put in comment the autonomous part - I was pointing out that your use of an autonomous transaction in the part that you said is probably wrong, unless you are trying to log on each attempt insert, regardless of whether it succeeds, and (as you saw), a trigger can not capture each insert attempt if the data type is not valid (for example). Even if she did it, insert it into your trigger would fail (assuming you have the same types of data on emp_v as on emp)

  • Pipeline raised ORA-06519 function: active autonomous transaction detected

    Hi all

    My name is John and I have a problem I need to share with you the guru and the experts. I created the following function of pipeline under user Oracle ABC:

    CREATE or replace FUNCTION SomeFunction(p_from_date DATE, p_to_date DATE) T_TAB_A RETURN pipelined
    IS
    PRAGMA autonomous_transaction;
    BEGIN
    DELETE FROM temp_rcm;

    INSERT INTO temp_rcm
    SELECT * FROM int.facility fd.
    int. Capacity co
    WHERE co.resource_name = fd.resource_name
    AND co.trade_date = fd.trade_date
    AND co.trade_date BETWEEN p_from_date AND p_to_date;

    COMMIT;

    FOR rec IN (SELECT co.*
    OF temp_rcm co
    o left join int.outage
    WE (o.flag = 'Y')
    AND o.reason_flag = 'F'
    AND o.INTERVAL = co. INTERVAL OF
    AND co.resource_name = o.resource_name)
    ORDER OF co. MEANTIME,
    Co.Name) LOOP
    pipe ROW (T_A (CRE. INTERVAL, rec.trade_date,
    Rec.resource_name, Rec.day_of_week_long, rec.working_day, rec.peak));
    END LOOP;

    RETURN;
    END SomeFunction;


    I could compile and create the function SomeFunction successfully, but when I executed the following command:

    Select * from table (SomeFunction (to_date ('01 / 01/2010 ', to_date('01/01/2010')));)

    I went with the Oracle error: ORA-06519: active autonomous transaction detected and restored

    I searched on the web, such Oracle error occurs when the function has a missing "COMMIT" or "ROLLBACK" command inside an autonomous_transaction. But the fact is that I have already included the "COMMIT"; in the function. I suspected that the error was caused by the paintings that I did against (such as int.facility and int.capacity) were all the views which belonged to another schema called int. Or is it something that miss me in the service? Thank you for your time and your help.

    Kind regards
    John

    This isn't how a ref cursor is used in general. See this thread: {: identifier of the thread = 886365}

    I can't really answer your question without knowing what kind of client you are using (Java, c#, etc.).

    However, the thread should shed a lot of light on the ref Cursor.

  • «Not in a position to authorize credit cards: gateway error.» Transaction, blocked by parameters in the FMF.

    Separated from: "what is the FMF settings? __"

    This doesn't help me.  All of a sudden, I can't use my online credit card.  I get a message saying: "your card has been blocked by FMF. settings.  I get this no matter where I'm trying to use it - it has nothing to do with PayPal.  But every search I did on this message always brings back me to PayPal.  Help!

    Hello

    I suggest you to contact the Banking Department appropriate to help unblock the account.
    PayPal offers users to its own service, called fraud management filters, or FMF, which can identify, report, or counteract potentially fraudulent transactions. Users can set up to the FMF to control possible on payments; flag, to ask for review or deny outgoing payments riskier; review and restrict incoming payments.
     
     
     
    Reference:
     
     
     
     
    I hope this helps.
  • Block insert exception

    I wonder if it is the exception-able to put and to insert in the exception block? What I would like is if date2 is null kickoff a mistake. If there is no recording where date2 is null, then go ahead and insert the new record. Is this a common practice or should I use sql % rowcount or County in variable and check if greater than 0?

    create or replace
    PROCEDURE X_INSERT
    (NUMBER OF P_ID,
    P_DATE1 DAY,
    DATE OF P_DATE2
    )
    AS
    a NUMBER;
    BEGIN
    Select code from one of X where P_ID = ID
    AND DATE_2 IS SET TO NULL;
    If sql % found then
    raise_application_error (-20000, "file exists");
    END IF;
    exception
    When no_data_found then
    Insert for X values (P_ID, P_DATE1, P_DATE2);
    END X_INSERT;

    I, personally, would work on the principle that exceptions are just that: exceptions. In other words, for the treatment of things you didn't really expect to happen (or hope does not happen).

    If this is the normal treatment to insert a line, if you can't find the data and that you do not normally to find data - then do it in the body

    Throw an exception if you find not data you indicate that something has gone seriously wrong.

  • Why do I get annoying pop-up ads with sound even when I have all the pop ups blocked without exception in the options?

    The pop - ups seem to come from Firefox. Is it possible to stop? They are noisy, not desired, disturb when online. They interrupt brutally.

    See this: http://kb.mozillazine.org/Popups_not_blocked

  • Blocker 'exceptions' does not work

    I've identified a site for which we should be able to jump - rises. (Homepage of the Multnomah County Library and the library catalogue page.) Details of items on a page of catalog are provided in windows Firefox v. 9.0.1 treats like pop-ups. (Version 3.6.25 does not block these "pop-up windows" even if there is no listed anomalies. The yellow warning bar appears for a split second and then I returned to the page from where I started.

    Disable blocker completely solves this problem, but is not a desirable arrangement.

    The following article contains information on the blocker popup ads and some troubleshooting steps. Please read this article, I believe that this will help you get this problem is resolved.

  • Continue the block after the exception management

    The guys in the slot block.

    create or replace procedure proc_case
    (p_in IN number)
    is
    begin
    case p_in
    when 1 then
    dbms_output.put_line('its one'); 
    when 2 then
    dbms_output.put_line('its two'); 
    end case;
    dbms_output.put_line('after the exception handler'); 
    exception when case_not_found then
    dbms_output.put_line('its not found'); 
    end;
    

    When the procedure is executed as follows.

    begin
    proc_case(3);
    end;
    

    It shows the statement in the block of exception, but after that it does not run the statement following the exception handler and the outputs of the block, how can I execute the statement after the end case statement. I do not use the Else statement in case because I wanted to understand the logic of this block.

    CREATE OR REPLACE

    PROCEDURE proc_case

    (

    p_in in NUMBER)

    IS

    BEGIN

    BEGIN

    P_in CASE

    WHEN 1 THEN

    dbms_output.put_line ('the one');

    WHEN 2 THEN

    dbms_output.put_line ('two');

    END CASE;

    EXCEPTION

    WHEN case_not_found THEN

    dbms_output.put_line ("' its not found");

    END;

    dbms_output.put_line ("' after the exception handler");

    END;

  • Record details of exception (PL/SQL)

    Hello

    After getting an exception in the stored procedure, I want to record the name of the procedure and the database server that triggered the exception.
    For example. proc_calculate_interest, DB_SERVER1

    I tried to use SQLERRM, but it gives me the error message.

    Thanks in advance.

    Uday

    To retrieve the name of the db server, you can use all the sql code following the extraction of the client machine

    select global_name from global_name;
    
    SELECT UTL_INADDR.get_host_name from dual
    
    SELECT UTL_INADDR.get_host_address from dual
    

    Create a record in table and an autonomous transaction procedure to store the error of errors. Call this proc in exception block when it occurs. See the code below.

    create table tab_excep
    (obj_name varchar2(100),
    p_excep_code number,
    p_dbname varchar2(100)
    );
    
    create or replace procedure LOG_ERROR(p_name varchar2,p_err number,p_dbname varchar2)
    is
    pragma autonomous_transaction;
    begin
    insert into tab_excep
    values
    (p_name,p_err,p_dbname);
    commit;
    end;
    
    create or replace procedure PROC_TEST is
    
    l_dbname varchar2(100);
    begin
    
    select global_name into l_dbname from global_name;
    --------
    --------
    --------
    --------
    --------
    EXCEPTION
    
    WHEN  THEN
    LOG_ERROR('PROC_TEST',SQLERRM,l_dbname);
    
    end;
    
  • Autonomous Tranasction in Java

    How can I use a similar concept as autonomous transaction in java. My requirement is to connect to a particular block, and should not have any impact on the transaction. How can I achieve this? Thank you in advance

    In EJB, there is something similar (if you don't want to go with multiple db connections), known as nested transactions - see http://stackoverflow.com/questions/10817838/ejb-3-0-nested-transaction-requires-new or Java Enterprise Stuff: EJB transactions: deepening (search for REQUIRES_NEW)

  • details about exceptions

    Hi Master,

    Y'day I attended an interview. He asked me several questions... but I not answered two questions. So, I am rejected me. Please notify these two questions.

    (Q) I have A procedure. In what I call procedure B. But A procedure has part of exception... Procedure B is not exception. If procedure B you have a mistake, what is the result?

    I said... we will have an error message.  He is not satisfied.

    (Q) what is internally pragma autonomous transaction do?

    Please advise...

    Thanks to the adv.

    SA


    something to play with

    declare

    CX varchar2 (50): = ' 10.987654321098765432109876543210987654321098765';

    CY varchar2 (50): = ' 9.123456789012345678901234567890123456789012345';

    x float;

    float of y;

    procedure has (x outside the float in the float y) is

    Start

    x: = x / y;

    exception

    When zero_divide

    then X: = null;

    while others

    then lift;

    end;

    b procedure (x float, y float in) is

    Start

    a(x,y);

    x: = x y;

    end;

    Start

    dbms_output.put_line ('chr_x =' |) CX);

    dbms_output.put_line ('chr_y =' |) CY);

    x: = to_number (cx);

    y: = to_number (cy);

    dbms_output.put_line ('num_x =' | to_char (x) |'; num_y = ' | to_char (y));

    b(x,y);

    dbms_output.put_line (' x_nouveaux = ': case when x is null then 'null' other end to_char (x) |) ("(must be num_x - in theory)');

    end;

    NORMAL PROCESSING:

    chr_x = 10.987654321098765432109876543210987654321098765

    chr_y = 9.123456789012345678901234567890123456789012345

    num_x = 10.98765432109876543210987654321098765432; num_y = 9.12345678901234567890123456789012345679

    x_nouveaux = 10.98765432109876543210987654321098765434 (should be num_x - in theory)

    Statement processed.

    ZERO_DIVIDE EXPECTED:

    chr_x = 10.987654321098765432109876543210987654321098765

    chr_y = 0

    num_x = 10.98765432109876543210987654321098765432; num_y = 0

    x_nouveaux = null (should be num_x - in theory)

    Statement processed.

    UNEXPECTED EXCEPTION ('? (' is entered as cy) :

    ORA-06502: PL/SQL: digital or value error: character of number conversion error

    Concerning

    Etbin

Maybe you are looking for