Concurrency when inserting in the same table

Hi,
I have a report used by several users and in this record there is a sentence to insert in a z table. My question is, what happens whether two or more users are inserting records in that table at the same time?  There is a concurrency problem, isn't there?
How does SAP manage this issue? or, what must I do in this case?
Thanks in advance.
Regards.

Hi David,
As SAP applications are accessed by many end users at same time, SAP has concept called LOCKING of particular tables involved in the transaction.
You can achieve your requirement as below
Go to t-code SE11, and create a lock object for your Ztable
Now, system create 2 function modules - 1 for locking ENQUEUE_* & other for un-locking DEQUEUE_*  ( search for function module in SE37 )
Before saving data to ZTABLE, call function module ENQUEUE_* to lock the table for writing data, if locking fails, means there is somebody already working on it, hence you can display error message
After Save action, you can unlock the table by using FM ... DEQUEUE_*
Note: you can lock and unlock event during DISPLAY/CHANGE mode if your requirement requires.
Hope this helps you.
Regards,
Rama

Similar Messages

  • MULTIPLE UPDATES/INSERTIONS TO THE SAME TABLE

    How can I update/insert mutiple rows into the same table from one form ?

    Hi,
    Using the portal form on table you can insert only a single row. You can use master-detail form to insert multiple rows.
    Thanks,
    Sharmila

  • Different number of rows when add/delete the same table

    Hi,
    i've a problem in a select statement.
    My database is a 9.2.0.8.
    select *
    from  tab1 t1,
            tab2 t2,
            tab2 t3
    where t1.id_c1 = 1
       AND t1.id_c2 = t2.id_c2
       AND t1.id_c2 = t3.id_c2
       AND t2.id_init = 3693
       AND t3.id_init = 3892;
    936 rows selected.if i change the query in:
    select *
    from  tab1 t1,
            tab2 t2
    where t1.id_c1=1
       AND t1.id_c2 = t2.id_c2
       AND t2.id_init in ( 3693,3892);
    61132 rows selected.Any ideas? what's wrong??
    Tnx
    Edited by: 842366 on 10-ago-2011 3.10
    Edited by: 842366 on 10-ago-2011 3.10

    You can see the difference yourself with this sample test data.
    SQL> with t_data1 as
    select 1 as id_c1,2 as id_c2 from dual union all
    select 2 ,2 from dual
    t_data2 as
    select 1 as id_c2, 3693 as id_init from dual union all
    select 1, 3693  from dual union all
    select 1, 3892t from dual union all
    select 1, 3892 from dual union all
    select 2, 3693 from dual union all
    select 2, 3892 from dual union all
    select 2, 3892 from dual
    select *
    from  t_data1 t1,
            t_data2 t2
    where t1.id_c1=1
       AND t1.id_c2 = t2.id_c2
       AND t2.id_init in ( 3693,3892);
         ID_C1      ID_C2      ID_C2    ID_INIT
             1          2          2       3693
             1          2          2       3892
             1          2          2       3892
    SQL> SQL>
    SQL>
    SQL>
    SQL> with t_data1 as
    select 1 as id_c1,2 as id_c2 from dual union all
    select 2 ,2 from dual
    t_data2 as
    select 1 as id_c2, 3693 as id_init from dual union all
    select 1, 3693  from dual union all
    select 1, 3892t from dual union all
    select 1, 3892 from dual union all
    select 2, 3693 from dual union all
    select 2, 3892 from dual union all
    select 2, 3892 from dual
    select *
    from  t_data1 t1,
            t_data2 t2,
            t_data2 t3
    where t1.id_c1 = 1
       AND t1.id_c2 = t2.id_c2
       AND t1.id_c2 = t3.id_c2
       AND t2.id_init = 3693
       AND t3.id_init = 3892;
         ID_C1      ID_C2      ID_C2    ID_INIT      ID_C2    ID_INIT
             1          2          2       3693          2       3892
             1          2          2       3693          2       3892
    SQL> We see that in both the queries, the no. of column returned are different. In first it is 4 and in 2nd it returns 6.
    Now ask yourself, what is the use of this query, and how I am suppose to use the values returned and also what is the purpose for each value.
    Once you have the answers for these questions, the requirement becomes more clearer, doubts vanish and more often you can do things yourself.

  • Parallel Insert statements (bulk) to the same table

    Hi,
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.
    Note that both will try to insert on the same table.
    Please let me know whether it is advisable or tell me an alternative way.
    Using...Oracle 11g DB.
    Regards
    Deep.

    935195 wrote:
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.Small number of rows. 50,000 rows can be inserted in seconds. Not sure why you want to split it. Parallel inserts into the same table is not usually a problem. Contention could be around free lists, initrans and so on - especially if using RAC and inserting something like 50,000+ rows every second. But the table defaults usually suffice.
    Note that both will try to insert on the same table.So what? This is exactly what Oracle expects and what it is designed to do.
    Please let me know whether it is advisable or tell me an alternative way.Well, you mentioned SQL worksheets - why? Exactly how does the INSERT statements look like? Where does the data to insert come from? Is shared insert cursors used (bind variables compulsory)? The bottleneck and problem could very well be on your side and not with the actual inserts into the table.

  • CLR trigger - handling multiple inserts at the same time

    Hi
    I've developed a CLR trigger which operates on inserts performed on a staging table. The trigger implements some business logic and then inserts or updates a record in a target table. Whether an insert or update is performed depends on whether
    a record with the same ID already exists in the target (i.e. a select * from target where ID = 123).
    This works fine in most scenarios, but occasionally I am getting duplicates in the target table and have noticed that this seems to occur when inserts on the staging table happen at exactly the same time (i.e. multiple inserts for the same ID at
    the same time). In this situation duplicates are created in the target table because at the time of the inserts, no record with that ID exists in the target table (i.e. the select returns no records), therefore a new record is created for each.
    Is there a known way to deal with this scenario? For example, would locking the target table on insert result in the subsequent selects against the target table waiting until the target table had been updated, therefore the select would return a record
    for the given ID.
    I didn't really want to lock the whole target table on insert, because there are potentially other users reading that table (selects) and these would also have to wait for the insert to complete.
    I'd appreciate any thoughts on how to deal with this and avoid duplicates in the target table. I'm unable to change the way the data is coming in to the staging table, so my trigger code must deal with the above scenario.
    Thanks in advance.
    John

    First if you do not want any duplicate values in a column (or combination of columns) you should add a constraint to ensure this is never possible. A
    unique index
    like this should do this trick.
    CREATE UNIQUE NONCLUSTERED INDEX [IX_yourIndexName] ON [dbo].[YourTableName]
    [yourColumn1] ASC,
    -- add more columns that make the unique combination that you don't want repeated
    You can then add a try/catch block in your trigger code, if you get an exception based on this index then the record was created by another executing instance of this trigger and in that case you should do an update (or not, not sure what the rest of your
    logic is) in your catch block. This is the easiest solution and does not involve table locks. The only drawback is the first one to commit the insert will win and you have no guarantee which process or data set that will be. Also i have no idea how big the
    table is, how frequently changes are made, and what the data type is so you should
    keep this in mind when creating your index so you don't run into unexpected high index fragmentation which can lead to performance problems when executing updates and inserts.
    You could also create a
    named transaction with scope serializable around your insert/update block and execute your reads using a
    NOLOCK hint
    which should allow them to retrieve uncommitted writes and not create a long wait. The downside is is that the data might not be 100% accurate depending on if a transaction fails or not if there happens to be an update at the same time as a select but maybe
    this is not a big deal to the calling code.
    -Igor

  • Possible solution to avoid deadlock when two inserts happen on same table from two different machines.

    Possible solution to avoid deadlock when two inserts happen on same table from two different machines.
    Below are the details from deadlock trace.
    Deadlock encountered .... Printing deadlock information
    Wait-for graph
    NULL
    Node:1
    KEY: 8:72057594811318272 (ffffffffffff) CleanCnt:3 Mode:RangeS-S Flags: 0x1
    Grant List 2:
    Owner:0x00000013F494A980 Mode: RangeS-S Flg:0x40 Ref:0 Life:02000000 SPID:376 ECID:0 XactLockInfo: 0x000000055014F400
    SPID: 376 ECID: 0 Statement Type: INSERT Line #: 70
    Input Buf: RPC Event: Proc [Database Id = 8 Object Id = 89923542]
    Requested by:
    ResType:LockOwner Stype:'OR'Xdes:0x0000002AA53383B0 Mode: RangeI-N SPID:238 BatchID:0 ECID:0 TaskProxy:(0x00000027669B4538) Value:0x10d8d500 Cost:(0/38828)
    NULL
    Node:2
    KEY: 8:72057594811318272 (ffffffffffff) CleanCnt:3 Mode:RangeS-S Flags: 0x1
    Grant List 2:
    Owner:0x0000000B3486A780 Mode: RangeS-S Flg:0x40 Ref:0 Life:02000000 SPID:238 ECID:0 XactLockInfo: 0x0000002AA53383F0
    SPID: 238 ECID: 0 Statement Type: INSERT Line #: 70
    Input Buf: RPC Event: Proc [Database Id = 8 Object Id = 89923542]
    Requested by:
    ResType:LockOwner Stype:'OR'Xdes:0x000000055014F3C0 Mode: RangeI-N SPID:376 BatchID:0 ECID:0 TaskProxy:(0x000000080426E538) Value:0x30614e80 Cost:(0/41748)
    NULL
    Victim Resource Owner:
    ResType:LockOwner Stype:'OR'Xdes:0x0000002AA53383B0 Mode: RangeI-N SPID:238 BatchID:0 ECID:0 TaskProxy:(0x00000027669B4538) Value:0x10d8d500 Cost:(0/38828)
    deadlock-list
    deadlock victim=process5daddc8
    process-list
    process id=process5daddc8 taskpriority=0 logused=38828 waitresource=KEY: 8:72057594811318272 (ffffffffffff) waittime=2444 ownerId=2994026815 transactionname=user_transaction lasttranstarted=2014-07-25T12:46:57.347 XDES=0x2aa53383b0 lockMode=RangeI-N schedulerid=43 kpid=14156 status=suspended spid=238 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2014-07-25T12:46:57.463 lastbatchcompleted=2014-07-25T12:46:57.463 clientapp=pa hostname=pa02 hostpid=1596 loginname=myuser isolationlevel=serializable (4) xactid=2994026815 currentdb=8 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
    executionStack
    frame procname=mydb.dbo.SaveBill line=70 stmtstart=6148 stmtend=8060 sqlhandle=0x03000800d61f5c056bd3860170a300000100000000000000
    INSERT INTO [dbo].[Prod1] .....
    inputbuf
    Proc [Database Id = 8 Object Id = 89923542]
    process id=process5d84988 taskpriority=0 logused=41748 waitresource=KEY: 8:72057594811318272 (ffffffffffff) waittime=2444 ownerId=2994024748 transactionname=user_transaction lasttranstarted=2014-07-25T12:46:57.320 XDES=0x55014f3c0 lockMode=RangeI-N schedulerid=39 kpid=14292 status=suspended spid=376 sbid=0 ecid=0 priority=0 trancount=2 lastbatchstarted=2014-07-25T12:46:57.440 lastbatchcompleted=2014-07-25T12:46:57.440 clientapp=pa hostname=pa01 hostpid=1548 loginname=myuser isolationlevel=serializable (4) xactid=2994024748 currentdb=8 lockTimeout=4294967295 clientoption1=671088672 clientoption2=128056
    executionStack
    frame procname=pa.dbo.SaveBill line=70 stmtstart=6148 stmtend=8060 sqlhandle=0x03000800d61f5c056bd3860170a300000100000000000000
    INSERT INTO [dbo].[Prod1]....
    inputbuf
    Proc [Database Id = 8 Object Id = 89923542]
    resource-list
    keylock hobtid=72057594811318272 dbid=8 objectname=pa.dbo.prod1 indexname=PK_a id=lock1608ee1380 mode=RangeS-S associatedObjectId=72057594811318272
    owner-list
    owner id=process5d84988 mode=RangeS-S
    waiter-list
    waiter id=process5daddc8 mode=RangeI-N requestType=convert
    keylock hobtid=72057594811318272 dbid=8 objectname=pa.dbo.prod1 indexname=PK_a id=lock1608ee1380 mode=RangeS-S associatedObjectId=72057594811318272
    owner-list
    owner id=process5daddc8 mode=RangeS-S
    waiter-list
    waiter id=process5d84988 mode=RangeI-N requestType=convert

    Don't know. Perhaps these can help. I scanned the second link but didn't see much about Ending Deadlocks. I'd say the Fourth link probably has better information than the first three links. But maybe read them all just in case the Fourth is missing something
    one of the first three have.
    Deadlocking
    Detecting and Ending Deadlocks
    Minimizing Deadlocks
    Handling Deadlocks in SQL Server
    Google search for "SQL Deadlock"
    La vida loca

  • Inserting a LONG to a BLOB in the same table

    I have a table with a LONG column and would like to concatenate all existing columns into a new column in the same table and define it as a BLOB. I'm trying to figure out a way to do this. I tried the following and got error message
    insert into cma_search_test
    select obj_id,
         line_id,
         doc_nmbr,
         supplier_part_num,
         mnfctr,
         mnfctr_part_nmbr,
         line_desc,
         ext_desc_txt,
         vend_name,
         cma_effect_dt,
         cma_expir_dt,
         last_updt_usr,
         last_updt_tmsp,
         obj_id||
         line_id||
         doc_nmbr||
         supplier_part_num||
         mnfctr||
         mnfctr_part_nmbr||
         line_desc||
         to_lob(ext_desc_txt)||
         vend_name||
         cma_effect_dt||
         cma_expir_dt||
         last_updt_usr||
         last_updt_tmsp "All_Columns"
    from cma_search
    to_lob(ext_desc_txt)||
    ERROR at line 22:
    ORA-00932: inconsistent datatypes
    Any help would be appreciated.
    Thanks,
    Tracy

    You cannot concatenate a LONG field. You will have to use a procedure to accomplish what you want.
    Use the DBMS_LOB package.

  • How to have concurrent CSV upload and manual edit in APEX on the same table

    Hi there,
    my users want to have csv upload and manual edit on apex pages functions together...
    it means they want to insert the data by csv upload and also have interactive report and form on the same table...
    so if user A changes something in csv file...then user B update or delete another record from apex fronted (manually in the apex form)...then after that user A wants to upload the csv file,the record was changed by user B would be overwritten ...
    So how can I prevent it?????

    Hi Huzaifa,
    Thanks for the reply...
    I'm going to use File Browser so that end users can upload the files themselves...
    after editing data by users...a manger going to review it and in case of approval , i need to insert the data to one final table....
    so it needs much effort to check two source tables and in case of difference between table of csv and other one...what to do...

  • Data of column datatype CLOB is moved to other columns of the same table

    Hi all,
    I have an issue with the tables having a CLOB datatype field.
    When executing a simple query on a table with a column of type CLOB it returns error [POL-2403] value too large for column.
    SQL> desc od_stock_nbcst_notes;
    Name Null? Type
    OD_STOCKID N NUMBER
    NBC_SERVICETYPE N VARCHAR(40)
    LANGUAGECODE N VARCHAR(8)
    AU_USERIDINS Y NUMBER
    INSERTDATE Y DATE
    AU_USERIDUPD Y NUMBER
    MODIFYDATE Y DATE
    VERSION Y SMALLINT(4)
    DBUSERINS Y VARCHAR(120)
    DBUSERUPD Y VARCHAR(120)
    TEXT Y CLOB(2000000000)
    NBC_PROVIDERCODE N VARCHAR(40)
    SQL> select * from od_stock_nbcst_notes;
    [POL-2403] value too large for column
    Checking deeply, some of the rows have got the data of the CLOB column moved in another column of the table.
    When doing select length(nbc_providercode) the length is bigger than the datatype of the field (varchar(40)).
    When doing substr(nbc_providercode,1,40) to see the content of the field, a portion of the Clob data is retrieved.
    SQL> select max(length(nbc_providercode)) from od_stock_nbcst_notes;
    MAX(LENGTH(NBC_PROVIDERCODE))
    162
    Choosing one random record, this is the stored information.
    SQL> select length(nbc_providerCode), text from od_stock_nbcst_notes where length(nbc_providerCode)=52;
    LENGTH(NBC_PROVIDERCODE) | TEXT
    -------------------------+-----------
    52 | poucos me
    SQL> select nbc_providerCode from od_stock_nbcst_notes where length(nbc_providerCode)=52;
    [POL-2403] value too large for column
    SQL> select substr(nbc_providercode,1,40) from od_stock_nbcst_notes where length(nbc_providercode)=52 ;
    SUBSTR(NBC_PROVIDERCODE
    Aproveite e deixe o seu carro no parque
    The content of the field is part of the content of the field text (datatype CLOB, containts an XML)!!!
    The right content of the field must be 'MTS' (retrieved from Central DB).
    The CLOB is being inserted into the Central DB, not into the Client ODB. Data is synchronized from CDB to ODB and the data is reaching the client in a wrong way.
    The issue can be recreated all the time in the same DB, but between different users the "corrupted" records are different.
    Any idea?

    939569 wrote:
    Hello,
    I am using Oracle 11.2, I would like to use SQL to update one column based on values of other rows at the same table. Here are the details:
    create table TB_test (myId number(4), crtTs date, updTs date);
    insert into tb_test(1, to_date('20110101', 'yyyymmdd'), null);
    insert into tb_test(1, to_date('20110201', 'yyyymmdd'), null);
    insert into tb_test(1, to_date('20110301', 'yyyymmdd'), null);
    insert into tb_test(2, to_date('20110901', 'yyyymmdd'), null);
    insert into tb_test(2, to_date('20110902', 'yyyymmdd'), null);
    After running the SQL, I would like have the following result:
    1, 20110101, 20110201
    1, 20110201, 20110301
    1, 20110301, null
    2, 20110901, 20110902
    2, 20110902, null
    Thanks for your suggestion.How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • Trigger to Update in the same table.

    Hi,
    I would like to create a trigger that when we insert into table ALL_CAPACITY_SNS_CELL1 it updates column Action on teh same table,if teher is an update, it will update the same table , column ACTION.
    This is what I have attempted but seems to be technically wrong.
    <pre>
    create table ALL_CAPACITY_SNS_CELL1
    ( A varchar2,
    action char(2),
    date_executed date);
    create or replace
    TRIGGER ALL_CAPACITY_HISTORY_TRACKING
    AFTER INSERT OR DELETE OR UPDATE ON ALL_CAPACITY_SNS_CELL1 FOR EACH ROW
    DECLARE
    v_operation VARCHAR2(10) := NULL;
    BEGIN
    IF INSERTING THEN
    v_operation := 'I';
    ELSIF UPDATING THEN
    v_operation := 'U';
    ELSE
    v_operation := 'D';
    END IF;
    IF INSERTING
    UPDATE ALL_CAPACITY_SNS_CELL1
    SET ACTION =v_operation,
    DATE_EXECUTED =sysdate ;
    ELSIF UPDATING THEN
    UPDATE ALL_CAPACITY_SNS_CELL1
    SET ACTION =v_operation,
    DATE_EXECUTED =sysdate ;
    END IF;
    END;
    </pre>

    CrackerJack wrote:
    But above query made all ACTION nul...so we shoudl after insert or update trigger right?Obviously it is not working. You modified my code the way it does not make sense.
    IF INSERTING
    THEN
    :NEW.ACTION := 'I';
    IF UPDATING
    THEN
    :NEW.ACTION := 'U';
    ELSE
    :NEW.ACTION := 'X';
    END IF;The code above checks if trigger fired on INSERT (IF INSERTING). In THEN branch of that IF you check if trigger fired on UPDATE. It makes no sense. Now, if you would use my trigger:
    SQL> create table ALL_CAPACITY_SNS_CELL1
      2  ( A varchar2(1),
      3  action char(2),
      4  date_executed date);
    Table created.
    SQL> create or replace
      2    TRIGGER ALL_CAPACITY_HISTORY_TRACKING
      3      BEFORE INSERT
      4         OR UPDATE
      5      ON ALL_CAPACITY_SNS_CELL1
      6      FOR EACH ROW
      7      BEGIN
      8          IF INSERTING
      9            THEN
    10              :NEW.ACTION := 'I';
    11            ELSE
    12              :NEW.ACTION := 'U';
    13          END IF;
    14          :NEW.DATE_EXECUTED := sysdate ;
    15  END;
    16  /
    Trigger created.
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('A')
      2  /
    1 row created.
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('B')
      2  /
    1 row created.
    SQL> alter session set nls_date_format='mm/dd/yyyy hh24:mi:ss'
      2  /
    Session altered.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    A I  05/13/2009 08:56:02
    B I  05/13/2009 08:56:09
    SQL> update ALL_CAPACITY_SNS_CELL1
      2  set a = 'X'
      3  where a = 'B'
      4  /
    1 row updated.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    A I  05/13/2009 08:56:02
    X U  05/13/2009 08:57:05
    SQL> update ALL_CAPACITY_SNS_CELL1
      2  set a = 'Y'
      3  /
    2 rows updated.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    Y U  05/13/2009 08:57:21
    Y U  05/13/2009 08:57:21
    SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('C')
      2  /
    1 row created.
    SQL> select * from ALL_CAPACITY_SNS_CELL1
      2  /
    A AC DATE_EXECUTED
    Y U  05/13/2009 08:57:21
    Y U  05/13/2009 08:57:21
    C I  05/13/2009 08:57:53
    SQL> SY.

  • Several FKs to the same table

    Hello,
    I have a master table with several Forign Keys – all of them to the same table. In order to display a column from the lookup table I'm using a select like:
    select     m.code,
         m.lcode1, f1.label,
         m.lcode2, f2.label,
         m.lcode6, f6.label
    from       MTABLE m,
         FTABLE  f1,
         FTABLE  f2,
         FTABLE  f6
    Where      m.lcode1 = f1.code  and
         m.lcode2 = f1.code and
         m.lcode6 = f6.codeIs this the correct and optimal way of doing it?
    Thanks for the help,
    Arie.

    Arie,
    It sounds like perhaps the best way might be to create your forms/reports based upon a view instead of the underlying tables (especially if you are running 10gR1 or 10gR2).
    I say this because:
    1. With 10g (maybe even back in 9i?), you can create INSTEAD_OF triggers, so instead of manipulating (insert, update or delete) the view, the trigger has the code to perform the action to the underlying base tables instead.
    2. This makes development easier, since all your joins are pre-defined in one place instead of re-creating them in numerous places.
    3. Grants can be issued to the views, instead of the various tables, with just select privs to the lookup tables.
    4. Change your join conditions to use the JOIN syntax, LEFT OUTER JOIN, etc., whatever is appropriate for your query. It's much easier to (eventually) figure out and maintain when you have multiple join conditions (especially against multiple tables), when any or all of them could null.
    For details on the JOIN syntax or the INSTEAD_OF triggers, try the on-line Oracle documentation (I'm at home today and don't have all my reference material handy).
    I'm using the above with great success (so far). I'm swamped with different work projects and different bosses and different priorities, so anything that makes my life easier is worth a couple hours of research, even if I have to do it from home in my off-time (if I can fit it into my schedule). I've been working on an HTMLDB (AppEx) application for over a year now, but I've probably only spent about 40-60 hours actually working on it, so I'm always forgetting most of what I've previously learned and done.
    Bill Ferguson

  • Insert data in same table based on some condition

    Hi. I am new to this forum.
    I have to write a stored procedure to Insert Data into a table say MYTABLE ,having structure as:
    Col1 Col2 Col3 ................ TotalInstallments CurrentInstallment PaidAmount MonthYear
    I have to insert all the data as it is in the same table(MYTABLE) except changing some fields on basis of some conditions:
    1. if PaidAmount>0 && CurrentInstallment<TotalInstallment then
    CurrentInstallment=CurrentInstallment+1
    2. In the MonthYear field I am having data in formate(month/year)ex. 01/2012, 11/2012 ....
    So I have to insert data by incrementing month and year. for example:
    if currentdata is 11/2012 then next data will be 12/2012
    But next will be 01/2013
    I have to select all the records which belongs to previous month(through MonthYear field ) and put checking & changes on each record of the selected data and then insert them into same table(MYTABLE).
    How to achive that?
    Thanks.

    978184 wrote:
    Every thing is working fine but some strange result as:
    when i run my Procedure TRANSFERDATATONEXTMONTH
    1. by Passing Value as : CUSTOMERID_var ='ABX101' and MONTHYEAR_var='12/2012' it insurts 5 rows
    which is correct , since I have 5 records where CUSTOMERID='ABX101' and MONTHYEAR='12/2012' and
    new 5 rows has CUSTOMERID='ABX101' and MONTHYEAR='01/2013' (all other values are as expected)
    2. now when i again run by passing values: CUSTOMERID='ABX101' and MONTHYEAR='01/2013' it inserts 10 records(just double )
    and new records has value CUSTOMERID='ABX101' and MONTHYEAR='02/2013' (while on the basis of condition CUSTOMERID='ABX101' and MONTHYEAR='01/2013' i have in my table only 5 records)
    and all records are duplicate. Some times it inserts three times , while on condition basis it should no. What is happening?Probably, meanwhile you were trying to Insert the First time and the second time, someone did run the procedure that Inserted 5 More records for 01/2013. And, hence your Second run inserted 10 records instead of 5.
    >
    Why it is inserting double of records while i have only 5 records on given condition? Am I missing some thing?Yes, you are. You are missing your Tables, Your Dummy/Sample Data, Working Procedure/Function that can be replicated.
    Without this, we cannot simply believe on assertions that Oracle is behaving incorrectly.
    In addition to this, the GetMonthYear function, should be scrapped. It is un-necessary, when the same logic can be achieved using Oracle ADD_MONTHS function (See my previous post). And you are storing the MonthYear in a Varchar field, which ideally should be a Date field. This eradicates the un-wanted need to cast from VARCHAR - DATE - VARCHAR.
    Please do make some time to read {message:id=9360002} and mentioned relevant details.
    And notice, the code difference in my previous post and in your code.
    Please use
    {noformat}
    (exactly as shown) above and below your code, that indents the code properly for better readability.
    {noformat}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Nsert/Update and Add Column at the same Table and at the "same" Time

    Hello,
    I want Insert/Update and Add Column at the same Table and at the "same" Time but in different sessions.
    Example:
    At first the "insert/update" statement:
    Insert into TestTable (Testid,Value) values (1,5105);
    After that the "add" statement:
    Alter table TestTable add TestColumn number;
    - sadly now I get the message: ORA-00054: resource busy and acquire with NOWAIT specified
    "insert/update" statement:
    Insert into TestTable (Testid,Value) values (2,1135);
    After that the execute commit.
    I don't know when the first session set the commit statement so I want that the DB the "Alter Table..." statement execute if it's possible.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.
    Thanks for ideas

    Well I want to walk in the rain without and umbrella and still stay dry, but it ain't gonna happen.
    You can't run a DDL statement against a table with transactions pending. Session 2 has to wait until session commits or rollbacks (or until the session is killed). That's just the way it is.
    This makes sense if you think about it. The data dictionary has to be consistent across all sessions. If session 2 was allowed to change the table structure whilst session 1 has a pending transaction then the database is in an inconsistent state. This is easier to see if you consider the reverse situation - the ALTER TABLE statement run by session 2 does a DROP COLUMN TESTID rather than adding a column: now what should happen to session 1's INSERT statement? You have retrospectively invalidated a statement that was perfectly legal when it was executed.
    If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.Fnord.
    Cheers, APC

  • Calculating average time from two records from the same table.

    Hi all
    I need to calculate the average time between two events that are recorded in the same table.
    The table is TMS_MESSAGE_AUDIT_LOG
    MESSAGE_ID VARCHAR2(16 BYTE) NOT NULL,
    MESSAGE_VERSION NUMBER(2) NOT NULL,
    CREATE_TM VARCHAR2(18 BYTE) NOT NULL,
    MESSAGE_STATUS VARCHAR2(30 BYTE),
    TRANSACTION_TYPE_NM VARCHAR2(30 BYTE),
    MESSAGE_TP VARCHAR2(3 BYTE),
    WORKFLOW_OBJECT VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_REQUEST VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_RETURN_CD VARCHAR2(30 BYTE) NOT NULL,
    AUDIT_ACTION VARCHAR2(255 BYTE),
    LAST_UPDATE_USER_LOGON_ID VARCHAR2(12 BYTE),
    LOCAL_TM VARCHAR2(18 BYTE) NOT NULL,
    LOCAL_TIME_ZN_NM VARCHAR2(70 BYTE) NOT NULL,
    LOCAL_DAYLIGHT_IN CHAR(1 BYTE) NOT NULL,
    FPRINT VARCHAR2(30 BYTE)
    What i now need is
    When the MESSAGE_ID is the same i need have the average time between when the MESSAGE_STATUS is AA and BB ( I need the time out of the CREATE_TM field )
    And this for every 15 minutes interval.
    Because this table will become BIG millions and millions of records it needs to be fast.
    Can anybody help me.
    Marcel

    Something like this?
    CREATE TABLE wr_test
    ( message_id                 VARCHAR2(16 BYTE) NOT NULL
    , message_version            NUMBER(2) NOT NULL  -- Assumption: Acknowledged ver > Received ver
    , create_tm                  VARCHAR2(18 BYTE) NOT NULL
    , message_status             VARCHAR2(30 BYTE)
    , transaction_type_nm        VARCHAR2(30 BYTE)
    , workflow_object            VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_request           VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_return_cd         VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , audit_action               VARCHAR2(255 BYTE)
    , last_update_user_logon_id  VARCHAR2(12 BYTE)
    , local_tm                   VARCHAR2(18 BYTE) NOT NULL
    , local_time_zn_nm           VARCHAR2(70 BYTE) DEFAULT 'GMT' NOT NULL
    , local_daylight_in          CHAR(1 BYTE) DEFAULT 'x' NOT NULL );
    INSERT ALL
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 1
           , create_tm
           , '(Receive)'
           , TO_CHAR(local_tm,'YYYYMMDD HH24:MI:SS') )
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 2
           , create_tm
           , 'Wait CLSB Ack'
         , TO_CHAR
           ( local_tm + NUMTODSINTERVAL(DBMS_RANDOM.VALUE(0,2e5),'SECOND')
           , 'YYYYMMDD HH24:MI:SS' ) )
    SELECT ROWNUM AS message_id
         , TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS create_tm
         , DATE '2000-01-01' + DBMS_RANDOM.VALUE(0,3) AS local_tm
    FROM dual CONNECT BY ROWNUM < 100000;
    WITH src AS
         ( SELECT message_id
                , message_status
                , message_version
                , TO_DATE(SUBSTR(local_tm,1,17),'YYYYMMDD HH24:MI:SS') AS dt
                , TO_DATE(SUBSTR(local_tm,1,8),'YYYYMMDD') AS dt_day
                , TO_CHAR(TO_DATE(SUBSTR(local_tm,10,8),'HH24:MI:SS'),'SSSSS') AS dt_sec
           FROM   wr_test
           WHERE  message_status IN ('(Receive)','Wait CLSB Ack') )
    SELECT dt_day + NUMTODSINTERVAL(period,'SECOND') AS dt
         , NUMTODSINTERVAL(AVG(elapsed),'DAY') AS avg_elapsed
         , NUMTODSINTERVAL(MIN(elapsed),'DAY') AS min_elapsed
         , NUMTODSINTERVAL(MAX(elapsed),'DAY') AS max_elapsed
         , COUNT(*)
    FROM   ( SELECT message_id
                  , message_status
                  , dt_day
                  , TRUNC(dt_sec/300)*300 AS period
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) AS ack_dt
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) - dt AS elapsed
             FROM   src ) cal
    WHERE  cal.message_status = '(Receive)'
    GROUP BY dt_day, period
    ORDER BY 1;Replace "wr_test" with "tms_message_audit_log" in the WITH subquery to test on your data.

  • Print parent to child link or path from the same table

    create table dummy(nodeid number, parentid number, nodename varchar2(20));
    insert into dummy values(100,-1,'homegoods');
    insert into dummy values(101,100,'kitchen');
    insert into dummy values(102,101,'skillet');
    select * from dummy gives:
    nodeid     parentid   node_name
    100         -1         HOMEGOODS
    101         100       KITCHEN
    102         101       SKILLETnote: parent id is the node id in the same table except for the top node.
    select nodeid, nodename, 'i want complete path from parent to child here' as path from dummy where nodeid = 102
    expected result
    nodeid   name     path
    102       skillet     homegoods>kitchen>skillethow can I do this ?
    thanks

    I thought it worked but I guess i am stuck in with real data . Please bear with me. I have never done hierarchical queries -
    there are more ids and fields that I have to put in the condition so here are the new create/insert sample stmnts.
    drop table dummy;
    create table dummy(hdr_id number,node_id number, config_item_id number, parent_config_item_id number,ps_node_name varchar2(20));
    insert into dummy values(35981400,     21400,     24547505,     -1,     'AT2200-10H');
    insert into dummy values(35981400,     21420,     24547506,     24547505,     'AT2200-10H-UWMOD');
    insert into dummy values(35981400,     37020,     24547564,     24547506,     'Corona Treater');
    insert into dummy values(35981400,     37021,     24547565,     24547564,     'None');
    insert into dummy values(35981400,     37024,     24547566,     24547506,     'Corona Type');
    insert into dummy values(35981400,     1877321,25766779,     24547566,     'None');
    select ps_node_name name,'path' from dummy where hdr_id = 35981400
    --I have to have hdr_id=something as a condition as there are numerous rows with different ids.
    so when I query for names in one hrd_id, I should get all names in that session, with paths linking parent to child upto current level.
    expected result :
    AT2200-10H     
    AT2200-10H-UWMOD        AT2200-10H>AT2200-10H-UWMOD
    Corona Treater        AT2200-10H>AT2200-10H-UWMOD>Corona Treater
    None                        AT2200-10H>AT2200-10H-UWMOD>Corona Treater>None
    Corona Type        AT2200-10H>AT2200-10H-UWMOD>Corona Type
    None                        AT2200-10H>AT2200-10H-UWMOD>Corona Type>None
    sorry for the confusion.
    Edited by: OAF-dev on Nov 18, 2009 4:24 PM

Maybe you are looking for