Insert/update of the XML help merge and to generate the sequence number

Hello

I'm working on Oracle 11 g.

I have a doubt with loading XML.
I get an xml and I need to insert or update data in a table. What I can accomplish by using the MERGE statement.
But there is a column in A table, I need to fill with a sequence number, based on the data sent in the xml file.
The XML does not send the data in this column.
And I have to make sure that sequence is created according to the order in which the records are present in xml.
For example the MERGER is insert five rows and update two lines and insert again 3 rows of xml in table A. The sequence number must be created in the same order for the column in the table.
Also for every new XML, the sequence starts with 1 and ends with the number of records in the xml file. I can't create a sequence and use the seq.nextval.

Please let me know, there is a way to achieve this.

Thank you!

Published by: 934451 on 8 August 2012 06:33

Published by: 934451 on 8 August 2012 06:50

Hello

As a result of your previous thread: {: identifier of the thread = 2403469}

You can use the clause for ORDINALITE in XMLTable to generate the necessary sequence:

MERGE INTO target_table t
USING (
  SELECT x.seq_num, x.pk_id, x.col1, x.col2, ...
  FROM XMLTable(
         '/root/record'
         passing my_xml_doc
         columns seq_num FOR ORDINALITY
               , pk_id   number       path 'ID'
               , col1    varchar2(30) path 'COL1'
               , col2    varchar2(30) path 'COL2'
               , ...
       ) x
) src
ON ( t.pk_id = src.pk_id )
WHEN MATCHED THEN UPDATE
 SET t.seq_num = src.seq_num
   , t.col1 = src.col1
   , t.col2 = src.col2
   , ...
WHEN NOT MATCHED THEN INSERT
 (seq_num, pk_id, col1, col2, ...)
 VALUES (src.seq_num, src.pk_id, src.col1, src.col2, ...)
;

Tags: Oracle Development

Similar Questions

  • Creating a trigger to insert delete update with the sequence number

    Hey all,.
    I have two tables. tbl_main, tbl_temp. Whenever a record is inserted, deleted, updated in tbl_main, I need to insert the records in tbl_temp. All field/column names are exactly the same, except that in tbl_temp, I now have a single column by using a sequence number, a column to determine if the record has been updated, remove, modified(hence the codes) and the date when a record has been added to the table.
    So far, that's what I have:

    create or replace
    audit_trg relaxation
    after update or insert or delete ON tbl_main
    for each line
    Start
    If the update can
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES
    (temp_seq.nextval, idx, mke, ctl, sysdate, 'U');
    ELSif INSERTION then
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES (temp_seq.nextval, idx, mke, ctl, 'n', sysdate);
    ELSIF deletion then
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES (temp_seq.nextval, idx, mke, ctl, would be ', sysdate);
    END IF;
    END audit_trg;

    I tried several combinations, but I get many compilation errors. This code looks good or I am the way of track? Thanks in advance.

    Who looks fine for me. What are the mistakes are you?

    Assuming that MKE and CTL are columns in the base table, your INSERT statements will insert either the: new.mke and: new.ctl values or the: old.mke and: old.ctl values in the table. Presumably, you could insert the: new values for inserts and updates, and the: old values for deletions.

    Justin

    Published by: Justin Cave 27 February 2009 16:08

    DOH! Just noticed the error...

  • Updated with the sequence column

    Hello

    Using oracle 10g on Windows XP

    I have a table that is having a lot of lines (75,000). I want to update the (recno) column with a sequence number of 1 to the order of 75,000 by MyColumn.

    I got below the response of:
    Re: Insert the sequence number in a table
    CREATE SEQUENCE SAMPLE_SEQ ALL CACHE 20 NOMAXVALUE MINVALUE NOCYCLE 1 INCREMENT OF 1 START WITH 1.

    But how do I get the first order column mycolumn. I mean that I want to give the sequence number; but in the order of MyColumn. It is our application need to have a column in a sequence.

    Thanks in advance.
    Concerning

    try something like:

    merge into mytable a
    using
    (select rid, rownum rnum from (
     select rowid rid
     from mytable
     order by mycolumn) b
    on (a.rowid = b.rid)
    when matched then update
       set a.recno = b.rnum
    
  • Generate the sequence number

    
    create table t
    (id int primary key,
    dt date,
    file_no int,
    batch_no int,
    data varchar2(5)
    );
    
    insert into t values (1,trunc(sysdate),23,113,dbms_random.string('a',5)); -- 1.1.1
    insert into t values (2,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.1
    insert into t values (3,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.2
    insert into t values (4,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.1
    insert into t values (5,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.2
    insert into t values (6,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.3
    --
    insert into t values (7,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.1
    insert into t values (8,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.2
    insert into t values (9,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.3
    insert into t values (10,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.1
    insert into t values (11,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.2
    insert into t values (12,trunc(sysdate),24,111,dbms_random.string('a',5)); -- 2.3.1
    
    
    

    Oracle 11.1

    How can given this structure and data, I generate sequence at the end of each line numbers? Basically, the sequence number (x.y.z) is such that x (1.n) is awarded for each unique value in file_no. In each x, y (1.n) is assigned for each unique value of batch_no. Within each y, z (1.n) is assigned for all records of this batch. Sample data shows only dt but all sequences must reset and start over when dt changes.

    I tried using row_number() over (partition by dt, file_no) and such but nothing quite gives me what I'm looking for.

    Help? Thank you

    Hello

    HELEN wrote:

    If you look at my CREATE TABLE, the ID column is a primary key and represents the order of the data in the file.

    Done batch_no = 100 come before or after 101?  Batch_no = 100 a ID so much until after the id for batch_no = 101.

    Good point, but that won't happen because of the way the 'record' is generated. All batch_nos will be contiguous. So if batch_no 100 comes earlier in the file as 101, it should get some 2nd highest sequence number. Otherwise, lower. Basically, the 2nd part of the sequence must simialar logical number to the 3rd party (i.e. order by id) but that messes things. Still struggle with it. Any help appreciated.

    I think I understand.  You say that, because of the way that the ID is issued, it wouldn't matter if you used the highest id of the batch_no, or the lowest id, or the average, or if you chose one at random; you would get the correct order in all cases.

    The following query uses the id low in the order file_no and batch_nos.

    WITH got_min_ids AS

    (

    SELECT id, dt, file_no, batch_no, data

    MIN (id) over (PARTITION BY dt

    file_no

    ) AS min_id_file_no

    MIN (id) over (PARTITION BY dt

    file_no

    batch_no

    ) AS min_id_batch_no

    T

    )

    SELECT id, dt, file_no, batch_no, data

    DENSE_RANK () OVER (PARTITION BY dt

    ORDER BY min_id_file_no

    )

    || '.'

    || DENSE_RANK () OVER (PARTITION BY dt

    file_no

    ORDER BY min_id_batch_no

    )

    || '.'

    || ROW_NUMBER () OVER (PARTITION BY dt

    file_no

    batch_no

    ORDER BY id

    ) AS seq

    OF got_min_ids

    ORDER BY dt, min_id_file_no, min_id_batch_no, id

    ;

    The main request is in fact what I posted before, but instead of

    "ORDER BY file_no" and "ORDER BY batch_no", she uses

    "ORDER BY min_id_file_no" and "ORDER BY min_id_batch_no".  These values are calculated in the subquery, got_min_ids.

    Output (including the additional sample data I posted):

    ID FILE_NO DT BATCH_NO SEQ DATA

    ---------- ----------- ---------- ---------- ----- ----------

    1 23 25 April 2014 113 dXAad 1.1.1

    2 345 23 25 April 2014 pumVG 1.2.1

    3 345 23 25 April 2014 jLnbO 1.2.2

    4 23 25 April 2014 543 xKhCL 1.3.1

    5 23 25 April 2014 543 JQoWk 1.3.2

    6 23 25 April 2014 543 YjJeC 1.3.3

    7 24 25 April 2014 333 WjQNE 2.1.1

    8 24 25 April 2014 333 ScWSL 2.1.2

    9 24 25 April 2014 333 pXDSD 2.1.3

    10 222 24 25 April 2014 OSajn 2.2.1

    11 222 24 25 April 2014 QNpix 2.2.2

    12 24 111 OwkjI 2.3.1 April 25, 2014

    91 100 99 25 April 2014 sRWmT 3.1.1

    93 100 99 25 April 2014 IAEFd 3.1.2

    92 101 99 25 April odQxh 2014 3.2.1

    I know you said that this situation is impossible (that is, if ID 91 and 93 have the same batch_no, then id 92 cannot have a different batch_no), but the application works even if this rule is broken.

  • How to find the sequence number of av

    Downloaded eset uninstaller, but he asked for the sequence number

    Hello Damien,.

    If you don't know, go to the icon of the program or file name and right-click on it and select properties and in the window that opens, read on the top row of tabs up until you get to the Details tab, click to open the tab. The sequence number is given here?

    If not, a freeware for you program called siw (System Information for Windows), download it here: http://download.cnet.com/SIW-Technician-s-Version/3000-2094_4-10915770.html . The application requires no installation, you simply double-click the name of the executable file, and the program opens to the software section. Scan down the list until you find the applications tab. Click to open your list and find details of eset and see if the sequence number is in the list.

    One of these two approaches should solve the problem for you. Let me know how you fare.

    Kind regards

    BearPup

  • Insert/update of the lines in tabular form from one table to another table

    Hello

    I'm having a tabular presentation for a table (equip_test) with 2 columns (equip_id, equip_name). I create a new

    Button (submit_alt) in this tabular form. I need to insert or update lines that are changed in this table to form

    another table (equip_staging) when you press the submit_alt button. How can I do this? How can I identify which lines are

    Insert or update? The process of the page I am trying since this button is
    begin
    
    FOR i in 1..APEX_APPLICATION.G_F01.count
    
    LOOP
    insert into equip_staging values(APEX_APPLICATION.G_F02(i),APEX_APPLICATION.G_F03(i));
    END LOOP;
    
    end;
    But it does not work. Help, please

    Thank you

    TJ

    Unchecking (does not) the column is a problem. Use this SQL instead (which is included in my examples):

    SELECT empno,
              empno
           || apex_item.hidden (33, wwv_flow_item.md5 (ename, sal, job))
                                                                    empno_display,
           ename, sal, job
      FROM emp
    

    and join this column hidden from your display column. In this way, it should work. When you feel there is no data found message in the treatment in a table, it will mean that the id does not exist.

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • Min and Max of the sequence number

    Hello

    I have a table called pins (lot number 4,
    Sequence number (8)
    );

    I have data in the table:
    batch sequence
    386 100
    386 101
    386 102
    386 800
    386 801
    1 387
    2 387

    I want to know by draw the low values and high for sequence number, is the result, I am looking

    batch min (sequence), max (sequence)
    386 100 102
    386 800 801
    387 1 2

    Oracle 10g rel2

    Thank you

    Hello

    You want something like this:

    WITH       got_grp     AS
    (
         SELECT     lot
         ,     seq_num          -- SEQUENCE is not a good column name
         ,     seq_num - ROW_NUMBER () OVER ( PARTITION BY  lot
                                                      ORDER BY      seq_num
                                          ) AS grp
         FROM    pins
    --     WHERE     ...     -- any filtering goes here
    )
    SELECT       lot
    ,       MIN (seq_num)          AS min_seq_num
    ,       MAX (seq_num)          AS max_seq_num
    FROM       got_grp
    GROUP BY  lot
    ,            grp
    ORDER BY  lot
    ,            min_seq_num
    ;
    

    If I understand the probem, you want to GROUP BY, but many does not define groups by itself: each contiguous set of seq_nums in a batch is a separate group. In each of these groups, the difference between seq_num and a meter which reflects the order of seq_num generated in the query (using ROW_NUMBER) will be constant.

    This assumes that seq_num is an integer, and this (lot, seq_num) is unique.
    If this is not the case, the above query will have a small adjustment.

    If you want to display the INSERT statements for your sample data, then I could test this.

  • Select the table column group and generate a sequence number

    I have to select data from a table column group and generate a sequence for every reset of the sequence from 1 to leave.

    For example:

    Data:
    Col1 Col2 Col3 Col4
    A NA KA-2009-08-13
    B NA KA-2009-08-13
    C NA KA-2009-08-13
    A NA KA-2009-08-13
    B NA KA-2009-08-13
    A NA KA-2009-08-13

    Expected results of the Select statement:
    Col1 Col2 Col3 Col4 Seq_No
    A NA KA-2009-08-13 1
    A NA KA-2009-08-13 2
    A NA KA-2009-08-13 3
    B NA KA-2009-08-13 1
    B NA KA-2009-08-13 2
    C NA KA-2009-08-13 1

    How can it be possible with a SELECT statement? Is it possible to assign the following numbers for a group of columns and put it back when it changes? In the above example, all columns are the key to generate the seq number

    I know that this can be done using procedures stored and that is how I do it now by introducing a temporary table.

    Can someone help me with this? Please let me know if the question is too vague to understand!

    Thank you
    Nachi

    Use the row_number() analytics.

    Ravi Kumar

  • With regard to the update of the sequence

    Hello

    We have OGG 11.1.1.1 and 11.2.0.3 DB.

    I have a small question about the improved Support of sequence
    According to the documentation:
    Installing new Oracle sequence support 
    Oracle GoldenGate version 11.1.1.1 contains improved sequence support. To enable this 
    support, you must install some database procedures that support the new FLUSH 
    SEQUENCE command. 
    Follow these instructions on the sourceand targetsystems. 
    1.  On the source and target Oracle systems, connect to SQL*Plus as SYSDBA. 
    2.  If you already assigned a database user to support the Oracle GoldenGate DDL 
    replication feature, you can skip this step. Otherwise, on both systems create a 
    database user that can also be the DDL user. 
    SQL> CREATE USER DDLuser IDENTIFIED BY password; 
    SQL> GRANT CONNECT,RESOURCE,DBA TO DDLuser; 
    3.  In the GLOBALS file on the source and target systems (create one if needed), add 
    the following parameter to designate the DDL schema. (If you already have this 
    parameter, skip this step.) 
    GGSCHEMA <schema> 
    4.  On both systems, run the sequence.sqlscript from the root of the Oracle 
    GoldenGate installation directory. This script creates some procedures for use by 
    Oracle GoldenGate processes. (Do not run them yourself.) You are prompted for 
    the schema information that you created in the first step. 
    SQL> @sequence.sql 
    5.  On the source system, grant EXECUTE privilege on the updateSequence
    procedure to a database user that can be used to issue the DBLOGIN command. 
    Remember or record this user. You use DBLOGIN to log into the database prior to 
    issuing the FLUSH SEQUENCE command, which calls the procedure. 
    SQL> GRANT EXECUTE on DDLuser.updateSequence TO DBLOGINuser; 
    6.  On the target system, grant EXECUTE privilege on the replicateSequence
    procedure to the Replicat database user. 
    SQL> GRANT EXECUTE on DDLuser.replicateSequence TO Replicatuser; 
    Immediately after you start the Oracle GoldenGate processes for the first time, issue the 
    FLUSH SEQUENCE command for each sequence (or with a wildcarded name). This 
    command alters the sequence to generate redo data. Replicat uses this redo to create an 
    initial synchronization point. You are prompted for this command in the upgrade steps.
    He mentions several times that you should have 2 users (e.g., DBLOGIN & DDLUser). But we only use a "GGS" to do anything. We have arrays of heartbeat, we use in the dblogin controls everything. It will be a problem during setup of this? Should we change our Setup to support this? I'm asking is because I have no environment to test it myself, so I'd be happy to have some feedback before you ruin my production environment.

    Thank you
    NACEUR

    It can be even given it required privileges.

    -Koko

  • Cannot perform the insert/update on the form of tables, due to the dynamic action

    Hi all

    I created a dynamic action that calculates multiple cells in a table.

    This feature works well, when I change the value of the associated cell then the computed value is changed by the dynamic action.

    But I am not able to insert or update the line in a table when the dynamic action is enabled. When I put the condition 'Never', then the line is inserted or updated without any problems.

    All guess where is the problem?

    Apex version: 4.1.1.00.23

    Jiri

    Nina wrote:

    I don't know why the 123,40 value (or other) is set to the next item in line (f09, fsc, etc.)
    >

    What is hidden and generated Apex elements are always included in the last cell (td) of the line. Thus, it has nothing to do with the next item, only the last cell.
    If you see the last cell of the 888 Page you will see probably the same type = "hidden" entries here also.

    Your problem is not related to the HTML fragment to the last cell in the row showing all those extra items, it's somewhere else.

    Oh, here comes the jQuery selector:

    var clickedRow = $(this.triggeringElement).closest('tr');
    
    $(clickedRow).children('td[headers="SAL"]').find("input").val(myCalculatedTotal);
    

    SAL, COMM, w/e. here you will find the TD with headers = "COMM" and all the input fields and the value of all the entries in total calculated. Your selection is not precise enough in this case.
    So, target the specific entry.
    With the code example:

    
    
    
    
    
    
    
    
    

    change the switch on

    $(clickedRow).children('td[headers="SAL"]').find('input[name="f08"]').val(myCalculatedTotal);
    
  • Insert/update of the individual fields in the DB Table

    So maybe I have a few noble desires, but I have my trying to find a way to change 1 single record (field) in a table.

    SCENARIO: I want to have a table that has the columns 'cid', 'class_name' and 'open_seats '... For example, if you have a line with values:

    1, namemw520, then a second, 25'

    2, nametr520, 32', and a third,.

    etc...

    Then in a form when the person fits and chooses a class, into submission, he will subtract one from the open_seats column and affect only the row of the selected class_name.

    WHAT I TRIED:

    So far, the only thing I can think is to have several queries to several tables in a line, and then update a form based on a selection of drop-down list doesn't seem to work, in addition, there are like 30 classes and I don't want to create tables of 30 DB, if it can be avoided. Or I'm WAY over my head on this one?

    Any help would be appreciated.

    TIA

    A more standardized design of database win the obligation to do something.

    Consider a design where your table has a field of ability instead of a seats_remaining.  Once you have configured a class, you should not change this value.  Then, as people sign up, you fill in a many-to-table number.  I hope that you are already doing.  Then to see how many points you have left, you do something like this:

    Select the capacity-

    (select count (*)

    your many at table number

    where is this class) seats_remaining

    your table class

    where is this class

  • How to capture information on what program is inserting/updating of the data in the table?

    Hello


    I'm working on an application where we have an ABC chart that has a STATUS column. This column is updated from somewhere.

    However, we are unable to determine where this COLUMN is updated. I checked the DBA_SOURCE table to see if this table is updated from any oracle proc / function. But isn't.

    Is there anyway that I can identify what program will update this table? I can create a before update trigger but I'm not sure if that I can capture program (shell script / informatica workflow) that is updated in this table.

    You can use in a trigger SYS_CONTEXT 'USERENV' information ' MODULE'

    create table mytable
    (
      col1   VARCHAR2(10)
    , col2   VARCHAR2(50)
    );
    
    create or replace trigger mytable_bi_trigger
    before insert
    on mytable
    for each row
    begin
    
        :new.col2 := SYS_CONTEXT('USERENV','MODULE');
    
    end;
    /
    
    -- from Toad
    insert into mytable(col1) values('Test 1');
    commit;
    -- From sqlplus
    insert into mytable(col1) values('Test 2');
    commit;
    
    select * from mytable;
    
    COL1       COL2
    ---------- --------------------------------------------------
    Test 1     TOAD 11.0.0.116
    Test 2     SQL*Plus        
    

    You can also capture a lot more information (host name of the client, the os user, etc.).

    See http://docs.oracle.com/database/121/SQLRF/functions199.htm#SQLRF06117

    Kind regards.

    Alberto

  • Is there a way to insert/update of the .js files in a .oam after publication?

    I'm working on a pretty animated project complex that uses of Commons of edges, and jQuery UI. I use Edge animate CC 2014 because 20141 broke some of these features and I was already too far into the project of updating the code.

    When I test the project through 'Preview in browser' everything works fine. But when I publish as a .oam file or in the web, the project is just broken. Interactive elements which depended on the Commons of edges have disappeared.

    I've narrowed the problem down to the three files 'index_edge.js', 'index_edgeActions.js' and 'index_edgePreload.js '. If I copy the work from the Animate project directory files and replace the versions published, the web export works. I guess that Edge animate compresses the code in these files and that is break something. However, I need a file .oam so that it can be used by the person next to the chain. Is it possible to replace these three files with versions of 'work' in the .oam file?

    Hello

    Open your edgeProject/index_edgeActions.js.Replace what follows with the comment of a single line. Open edge animate 2014 and publish again. Published content works

    /*================================================================================

    change Q number to match the circuit breakers | Q should = circuit breakers + 1 to the account of the value 0 if there is no BK0

    ____

    |    |

    |    |

    |    |                   DOUBLE CHECK BECAUSE OF BK0

    |    |

    |    |

    |    |

    __|    |__

    \        /

    \      /

    \    /

    \  /

    \/

    ================================================================================*/

    Like this.

    //================================================================================

    change Q number to match the circuit breakers | Q should = circuit breakers + 1 to the account of the value 0 if there is no BK0

    //         ____

    //        |    |

    //        |    |

    //        |    |                   DOUBLE CHECK BECAUSE OF BK0

    //        |    |

    //        |    |

    //        |    |

    //      __|    |__

    //      \        /

    //      \      /

    //        \    /

    //         \  /

    //          \/

    //================================================================================

  • Restrict the insert, update, delete the other user table

    I created a new database user. I have granted the privileges system into a TOAD.

    • Select any table
    • alter any table
    • delete a table

    I found that account can select, alter, drop table arrays of other schema. So how I can limit the which account to modify, remove only its tables belonging and select table of all the schema?

    Is there the ALTER table, ALTER view, ALTER procedure, ALTER synonym, DROP table, DROP view, DROP procedure, DROP synonym system privileges? How can I grant it without ANY system privileges?

  • Try to update Windows XP SP3 Media Center by using Windows Update, get the error number: 0 x 80070424

    When you use Windows Update Center for Windows XP Media Center with Service Pack 3 installed, I now get the following message is displayed:

    [Error number: 0 x 80070424]
    The website has encountered a problem and cannot display the page you are trying to view. The options provided below may help you solve the problem.

    For self-help options:

    To support options:

    I looked at the FAQ which makes no mention of SP3 but support States SP2 is underway, can you help me?

    Hey PABear and John_P.

    I found another link, and it's worked perfectly

    http://www.techiecorner.com/112/error-number-0x80070424-in-Windows-Update-solution/

    Thanks a lot for your help, definetitely remember Windows Fix It for later use

    Dave

Maybe you are looking for