Transactions within/across procedures

Hi,
I am new to oracle. I would like to know if a savepoint can be started at a higher level procedure, say proc_nestedlevel_0, and the same transaction continue down through lower level procedures proc_nestedlevel_1...2 . . .3 . . .proc_nestedlevel_n? The lower level procedures have dml statements. After processing the lower level procedures I try and rollback in the proc_nestedlevel_0 but the savepoint is no longer recognized and an exception is thrown. If it is possible to do this, could someone provide me an example as to how? I am finding in order for transaction technology to work in oracle procedures, you have to set a savepoint and have all of the DML statements in the same procedure. Only then will any savepoints be "recognized" as being set.
Any help is appreciated.
Thanks.

If it is possible to do this, could someone provide me an example as to how?
SQL> create or replace procedure p_2th_level
  2  is
  3  begin
  4   insert into t values(3);
  5   rollback to point_0;
  6  end;
  7  /
Procedure created.
SQL> create or replace procedure p_1th_level
  2  is
  3  begin
  4   insert into t values(2);
  5   p_2th_level;
  6  end;
  7  /
Procedure created.
SQL> create or replace procedure p_0th_level
  2  is
  3  begin
  4   insert into t values(1);
  5   savepoint point_0;
  6   p_1th_level;
  7  end;
  8  /
Procedure created.
SQL> select * from t;
no rows selected
SQL> exec p_0th_level
PL/SQL procedure successfully completed.
SQL> select * from t;
        ID
         1
I try and rollback in the proc_nestedlevel_0 but the savepoint is no longer
recognized and an exception is thrown. Don't you complete transaction inside "nested" procedures ? Check this:
SQL> create or replace procedure p_1th_level
  2  is
  3  begin
  4   insert into t values(2);
  5   commit;
  6   p_2th_level;
  7  end;
  8  /
Procedure created.
SQL> exec p_0th_level
BEGIN p_0th_level; END;
ERROR at line 1:
ORA-01086: savepoint 'POINT_0' never established
ORA-06512: at "SCOTT.P_2TH_LEVEL", line 5
ORA-06512: at "SCOTT.P_1TH_LEVEL", line 6
ORA-06512: at "SCOTT.P_0TH_LEVEL", line 6
ORA-06512: at line 1Rgds.

Similar Messages

  • Transaction Handling across Procedures

    In the ODI Best Practice Guide for Data Warehouses I came across the following (page 100):
    "ODI procedures include an advanced mechanism for transaction handling across multiple steps or even multiple procedures."
    It states that transaction handling can occur across multiple procedures. I could not get this to work.
    I created a procedure with just one step that inserts into a table. In the step I have set the Transaction dropdown to Transaction 0 and the Commit dropdown to No Commit. However, when I execute the procedure the insert is committed as we terminate the session.
    Any ideas how this commit can be prevented?

    ok, I figured out that parameters to the JDBC driver can be specified at the properties tab of the data server.
    So I presume this will be autocommit = false or sth. similar
    I still have to try this out.

  • Sp_executesql vs transaction statement within Stored Procedure

    Experts,
    Any difference between sp_executesql vs Transaction/Commit statement or try/catch block within Stored Procedure?
    What is the best practice to use and why?
    Thank You
    Regards,
    Kumar
    Please do let us know your feedback. Thank You - KG, MCTS

    Your question is a bit strange. sp_executesql is used for dynamic SQL. Unless the problem demands dynamic SQL and, therefore, sp_executesql, there is no need to use it.
    For a single statement I would not use transaction and try/catch. For multiple statements you do need to use transaction. It's up to you if you want to use try/catch in the SP or not and trap the error in the client application.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Shrink file (log) from within a procedure

    I'd like to incorporate the DBCC shrinkfile command to my maintenance procedure. This procedure gets called after I've finished my weekly importing process. I only need to shrink the log files as almost all the modifications are either a record update or
    an insert (there are very few deletions done). I need to do this across several databases and for software maintainability would prefer to have only the one procedure.
    My issue is that there does not seem to be a way to point to the various databases from within a procedure to preform this operation. Also the maintenance plan modules have a shrink database operation but I don't see a shrink file operation so that doesn't
    appear to be an option.
    Have I overlooked something or is it not possible to preform a shrink file operation for the transaction log files for multiple databases?
    Developer Frog Haven Enterprises

    Thank you for your response. While I did not use your answer verbatim it did lead me to my solution as I only need to preform the shrink operation on 4 out of the 7 databases in my SQL instance.
    FYI my final solution was...
    -- shrink the log files
    DECLARE @sql
    nvarchar(500);
    SET @sql
    =
    'USE [vp]; DBCC SHRINKFILE (2, 100);';
    EXEC
    (@sql);
    SET @sql
    =
    'USE [vp_arrow]; DBCC SHRINKFILE (2, 100);';
    EXEC
    (@sql)
    Developer Frog Haven Enterprises

  • Delay in execution of statements within a procedure!

    Dear All,
    My Database is Oracle 11gR2 on Linux.
    I have to schedule delete in 5 tables. For this i will write a procedure with delete queries and schedule the procedure to run daily in night.
    I want to give delay in the execution of delete queries within procedure? How can i add this functionality within a procedure?
    I don't want to lock the tables as other queries may be accessing the same table meanwhile.
    Looking for your help.
    Regards,
    Imran

    Other queries accessing the table meanwhile is a perfectly normal reason to lock the tables, as writers don't block readers.
    Implementing 'delays' is definitely an amateurish hack to result into more problems.
    Locking and transactions are one of the core functions of any RDBMS, and it is better to understand them, than to implement hack on hack on hack to turn a Ferrari like Oracle in a broken bike with a flat tire.
    After several years of asking doc questions you should know better.
    BTW can you explain why you end all of your questions with an unnecessary exclamation mark?
    If you can't explain this, can you stop doing so?
    There is no reason to yell here.
    Thank you
    Sybrand Bakker
    Senior Oracle DBA

  • PL/SQL: Executing a procedure from within another procedure

    Hello, I'm a newbie and I need help on how to execute procedures from within another procedure. The procedure that I call from within the procedure have return values that I want to check.
    I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    but I get the error message:
    PLS-00103: Encountered the symbol "USER_GET_FORUM_INFO" when expecting one of the following::= . ( @ % ; immediate
    The symbol ":=" was substituted for "USER_GET_FORUM_INFO" to continue.
    And when I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    I get the error message:
    PLS-00222: no function with name 'USER_GET_FORUM_INFO' exists in this scope
    PL/SQL: Statement ignored
    The procedure USER_GET_FORUM_INFO exists. (don't understand why it says "no FUNCTION with name", it's a procedure I'm executing)
    I'm stuck so thanks for any help...
    Below is all the code. I'm using Oracle 9i on RedHat Linux 7.3.
    ================================================================================
    CREATE OR REPLACE PROCEDURE user_forum_requestsaccess (
    p_forumid IN NUMBER,
    p_requestmessage IN VARCHAR2
    AS
    var_forumid NUMBER;
    var_forum_exists NUMBER;
    var_forum_access NUMBER;
    request_exists NUMBER;
    var_forumname VARCHAR2(30);
    FORUM_DOESNT_EXIST EXCEPTION;
    FORUM_USER_HAS_ACCESS EXCEPTION;
    FORUM_REQUEST_EXIST EXCEPTION;
    BEGIN
    SELECT SIGN(NVL((SELECT request_id FROM forum.vw_all_forum_requests WHERE forum_id = p_forumid AND db_user = user),0)) INTO request_exists FROM DUAL;
    EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    IF var_forum_exists = 0 THEN
    RAISE FORUM_DOESNT_EXIST;
    ELSIF var_forum_access = 1 THEN
    RAISE FORUM_USER_HAS_ACCESS;
    ELSIF request_exists = 1 THEN
    RAISE FORUM_REQUEST_EXIST;
    ELSE
    INSERT INTO tbl_forum_requests VALUES (SEQ_TBL_FORUM_REQ_REQ_ID.NEXTVAL, SYSDATE, p_requestmessage, p_forumid, user);
    INSERT INTO tbl_forum_eventlog VALUES (SEQ_TBL_FORUM_EVNTLOG_EVNT_ID.NEXTVAL,SYSDATE,1,'User ' || user || ' requested access to forum ' || var_forumname || '.', p_forumid,user);
    COMMIT;
    END IF;
    EXCEPTION
    WHEN
    FORUM_DOESNT_EXIST
    THEN RAISE_APPLICATION_ERROR(-20003,'Forum doesnt exist.');
    WHEN
    FORUM_USER_HAS_ACCESS
    THEN RAISE_APPLICATION_ERROR(-20004,'User already have access to this forum.');
    WHEN
    FORUM_REQUEST_EXIST
    THEN RAISE_APPLICATION_ERROR(-20005,'A request to this forum already exist.');
    END;
    GRANT EXECUTE ON user_forum_requestsaccess TO forum_user;
    ================================================================================
    Regards Goran

    you don't have to use execute when you want to execute a procedure (only on sql*plus, you would use it)
    just give the name of the funtion
    create or replace procedure test
    as
    begin
        dbms_output.put_line('this is the procedure test');
    end test;
    create or replace procedure call_test
    as
    begin
        dbms_output.put_line('this is the procedure call_test going to execute the procedure test');
        test;
    end call_test;
    begin
        dbms_output.put_line('this is an anonymous block calling the procedure call_test');
        call_test;
    end;
    /

  • Syntax for delete statement within a procedure

    within a procedure i tried to delete the table using
    delete table tablename;
    but it is showing error that
    PL/SQL: SQL Statement ignored
    PL/SQL: ORA-00903: invalid table name
    whether we have to use execute immediate delete table tablename;
    or this syntax is correct

    Hi ,
    i think if you want to use the delete
    then it shld be delete from tablename --> this'll delete all rows
    but if u want to use execute immediate then you might as well use TRUNCATE --> provided you need not have these data written to the log file (if you need for recovery later better use DELETE)
    i.e EXECUTE IMMEDIATE ('TRUNCATE TABLE tbl_name');
    hope this helps

  • Create a text file output from within a procedure

    I can output to a file from within SQL+ using the spool command but how do I do this from within a procedure?
    I have got a table called ABC and want to output columns A and B to a new text file based on variables pased through when the procedure is run, the name of the text file should be generated from a sequence?
    Any info appreciated.
    Cheers
    Cliff

    Hi,
    U can use UTL_File Package, But the only constraint is it will write the file only on the server m/c and not on the client m/c.
    Regards
    Gaurav

  • Call a procedure within a Procedure

    hi
    How can i call a procedure within a procedure
    Thanks in advance

    SQL> create procedure b as
      2  begin
      3  null;
      4  end;
      5  /
    Procedure created.
    SQL> create procedure a as
      2  begin
      3  b;
      4  end;
      5  /
    Procedure created.
    SQL>

  • How to call fn form within a procedure? - pl help

    Hello
    I have a procedure which has a set of statements that is called repeatedly.i would like to put them inside a function, passing an IN parameter as well. How to do that? and how do u call the fn from within the procedure?
    Pl help.
    rgds

    SQL> create or replace package calls is
      2      procedure proc ;
      3  end ;
      4  /
    Package created.
    SQL> create or replace package body calls is
      2      function func(p_param in number) return number is
      3      begin
      4          dbms_output.put_line('param is:'||p_param) ;
      5          return(p_param * 2) ;
      6      end ;
      7      procedure proc is
      8          ret_val number ;
      9      begin
    10          ret_val := func(100) ;
    11          dbms_output.put_line('ret_val='||ret_val) ;
    12      end ;
    13  end ;
    14  /
    Package body created.
    SQL> exec calls.proc ;
    param is:100
    ret_val=200
    PL/SQL procedure successfully completed.
    SQL>Message was edited by:
    Kamal Kishore

  • Open ERP transaction within CRM 2007 using wizard for transaction launcher

    Hello everybody,
    I am trying to launch a SAP ERP transaction within SAP CRM 2007 using the transaction launcher wizard.
    First I maintained all necessary setting for the RFC connections (in ERP and CRM) using for example transaction SM59 and BD87, e.g. the master data replication is working fine. Second I created a business object type based on the SAP Standard business object TSTC and set the u201CExecuteu201D method to u201CSynchronousu201D in SAP ERP.
    Afterwards I created the URL for our ITS server and started the transaction launcher in CRM. During the step u201CFurther technical detailsu201D I selected as transaction type u201CBOR transactionu201D and chose our logical system (ERP) and added our newly created BOR object type as well as the method u201CExecuteu201D. If I now press the u201CNextu201D button the error message u201CAn RFC destination could not be specified for the logical system XYu201D is shown.
    Any help is highly appreciated.
    Thanks lot and kind regards,
    Franziska

    Hi,
    The error you get is because the client you have mentioned for logical system mapping and the client in which you created the BOR object are not same.
    Remember, for sucessfull transaction Launcher Configurations,
    1) The client in which WEB UI Runs
    2) The Logical System mapping and client mentioned in ITS url
    3) The client is which you created the BOR object.
    4) The client on which you are configuring transaction launcher wizard
    ALL SHOULD BE THE SAME CLIENT, unless you are using the OWNLOGSYS concept for logical system mapping.
    For example,
    If my WEB UI is on client 200 of development system,
    then i must create TSTC based BOR in client 200 , Map logical system for client 200 and configure trnsaction launcher in client 200.
    In this approach, you cant transport the developments to other system and client ( like Quality and production system) , hence its advicible to create a logical system with name OWNLOGSYS. The name of logical system must be kept OWNLOGSYS in all the systems and clients so that then you can transport yout transaction launcher developments and the error you get now will not come. It its not possible to maintain the logical system with this name in all the system , then you will have to do as i mentioned in points 1 to 4.
    Hope this helps.
    Thanks & Regards,
    Suchita

  • Should we call a transaction within RFC

    Hi,
    I have a scenario like this.
    There is a portal application where in customers can create inbound delivery.
    What I am thinking is portal application will invoke a RFC passing the required data. Within the RFC I can write the BDC code for transaction VL31N to create inbound delivery.
    I just wanted to know if this is the correct way to do this.
    Should we call a transaction within a RFC ? What are the pros n cons associated with this ?
    Is there ne BAPI to create Inbound Delivery (VL31N) ?
    Regards,
    Nitin

    Hi Nitin,
    There's unfortunately no BAPI available to create an inbound delivery. So considering that, what you're doing is fine.
    I did not get what you meant by calling a transaction within an RFC in this context. If you're talking about a Portal application, what's the point in calling the transaction in the RFC ? Or did you mean that you want to use CALL TRANSACTION USING... ?
    Regards,
    Anand Mandalika.

  • How do i pass recordsets across procedures

    Hi,
    I wanted to know how to pass a record set from one procedure to another procedure using a table of a used defined type and how do i access the values from the recordset for any manipulation within the procedure..
    For eg i have a table/Ref cursor on a user defined type which has two columns empno,deptno... as a out parameter from a procedure... How do i take this in in a different procedure and access the values..
    Thanks
    Kiran

    Hello,
    Thanks for posting to the NI Discussion Forums.  The channel name attribute is one of the
    custom waveform attributes added by the DAQ driver software.  In addition to these items added by DAQ, it seems
    as though any custom attribute added to the waveform is not sent with
    the shared variable.  I have sent notice
    to R&D to take a look at this problem (issue 3VQEIA3A), but I do not have
    any sort of timeline on when/what will come of this.  For now, it looks like you will have to send
    any data about the waveform over to the Windows client machine separately.  For example, you could create a new variable
    of 2-D string data where you would populate the array with <key,value>
    pairs of the waveform data you are concerned with.  If you were interested in how to extract the channel
    name from the waveform, or any of the other properties set by the DAQ software
    check out the “details” in the context help for the “set waveform attribute”
    VI.
    Hope this helps!
    Travis M
    LabVIEW R&D
    National Instruments
    Attachments:
    waveformattributes.zip ‏36 KB

  • Calling a oracle procedure within a procedure - Urgent

    Hi
    Can some one tell me, how to call a oracle procedure within a procedure ?
    Thanks
    Murali

    You could always try looking in the manuals.

  • Executing procedure within same  procedure

    Hi all,
    Can any one tell me what would be happen if execute procedure within same procedure.
    Example :
    create or replace procedure print(str in varchar2)
    is
    begin
    print(str);
    dbms_output.put_line(str);
    exception
    when others then
    null;
    end print ;
    Regards,
    P Prakash

    But, you could call the same procedure in recursion procedure.
    This kind of procedure has :
    1) action of the recursion procedure
    2) condition to go out from the same recursive procedure
    SQL> create or replace procedure print(str in varchar2) is
      2      num_letters natural;
      3      string_tmp  varchar2(50);
      4  begin
      5      --  recursion action
      6      dbms_output.put_line(str);
      7 
      8      -- recursion condition
      9      num_letters := nvl(length(str), 0);
    10      if num_letters > 0 then
    11          print(substr(str, 1, num_letters - 1));
    12      end if;
    13  end print;
    14  /
    Procedure created
    SQL> exec  print('abcdefghijkl');
    abcdefghijkl
    abcdefghijk
    abcdefghij
    abcdefghi
    abcdefgh
    abcdefg
    abcdef
    abcde
    abcd
    abc
    ab
    a
    PL/SQL procedure successfully completed
    SQL>

Maybe you are looking for

  • Error : 'IDM_DataSource' Can't be created during IDM UI installation

    Dear All, I am installing SAP NW IDM 7.1 on Windows/MSSQL2005.Getting error while creating IDM_DataSource in installation phase of IDM UI. I am using JDBC 2.0 and JDK 1.6 Error java.rmi.RemoteException: com.sap.engine.services.dbpool.exceptions.BaseR

  • My Facebook app has disappeared

    My Facebook app has disappeared. It still appears in the purchased section of the my app store with status OPEN but when I click on OPEN nothing happens. I have restarted my iPad, restored settings and still no help. I was also advised to cable link

  • Style sheet cross browser issues

    Hi I am having a couple of issues with a test site i am producing The URL is above. All works ok in I.E.8 but in IE7 the links on the header are no longer in-line causing them to dissapear from view in some cases. And in IE6 the header size appears d

  • Get the inherited status of attributes

    Hi All,, I have a requirement as below: o     Every time the program reaches a line where the attribute ID and/or position ID is different from the previous line or for the first line, all attribute values for the dedicated position and attribute ID

  • Date picker  - removing calendar icon

    Helo, is there any way I can remove calendar icon from date picker? thanks for help! regards, drama9346