XML insertion/updation using merge and generate sequence number

Hi,
I am working on Oracle 11g.
I have a doubt with XML load.
I get an xml and I have to insert or update data into a table A. This I can achieve using MERGE statement.
But there is one column in Table A, that I need to populate with a sequence number, based on the data sent in the xml.
The xml does not send this column data.
And I have to make sure the sequence is created based on the order in which records are present in xml.
For example the MERGE is inserting five rows and then updating next two rows and again inserting 3 rows from xml into table A. The sequence number should be created in the same order for the column in table A.
Also for each new xml, the sequence starts with 1 and ends with the number of records in the xml. So I cannot create a sequence and use seq.nextval.
Please let me know, there is a way of achieveing this.
Thank you!
Edited by: 934451 on Aug 8, 2012 6:33 AM
Edited by: 934451 on Aug 8, 2012 6:50 AM

Hi,
Following up on your previous thread : {thread:id=2403469}
You can use the FOR ORDINALITY clause in XMLTable to generate the required 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, ...)
;

Similar Messages

  • Inserting values using merge

    Hi everyone,
    I need help with inserting values using merge.
    * I need to check all the units in a parent category. For example, NF_ARTICLECATEGORYID = 7462 is a parent category.
    * Im going to compare all the units in the parent category(7642) to the units in a subcategory (8053).
    * If the units in parent category(7642) is not present in the subcategory(8053) then the units will be inserted in the same table.
    table structure:
    Table name : ARTICLECATEGORYACCESS
    Fields: IP_ARTICLECATEGORYACCESSID
    NF_ARTICLECATEGORYID
    NF_UNITID
    NF_USERID
    N_VIEW
    N_EDIT
    Sample data:
    CREATE TABLE articlecategoryaccess (
    IP_ARTICLECATEGORYACCESSID NUMBER(5),
    NF_ARTICLECATEGORYID NUMBER (10),
    NF_UNITID NUMBER (10),
    NF_USERID NUMBER (10)
    N_VIEW INT,
    N_EDIT INT);
    INSERT INTO articlecategoryaccess VALUES (255583, 7642, 29727, NULL, 1 ,1);
    INSERT INTO articlecategoryaccess VALUES (243977,7642,29728, NULL, 1 ,1);
    INSERT INTO articlecategoryaccess VALUES (240770,7642,29843, NULL, 1 ,1);
    INSERT INTO articlecategoryaccess VALUES (243413,7642,29844, NULL, 1 ,1);
    INSERT INTO articlecategoryaccess VALUES (274828,7642,44849, NULL, 1 ,1);
    INSERT INTO articlecategoryaccess VALUES (274828,8053,44849, NULL, 1 ,1);
    Units ID 29727, 29728, 29843, 29844, 44849 has access to parent category 7642.
    The units id 29727, 29728, 29843, 29844 dont have access to subcategory 8053.
    29727, 29728, 29843, 29844 should be inserted in the same table and will have an access to 8053.
    After they are inserted, it should look like this
    IP_ARTICLECATEGORYACCESSID     NF_ARTICLECATEGORYID     NF_UNITID NF_USERID N_VIEW N_EDIT
    255583     7642     29727 null 1 1
    243977     7642     29728 null 1 1
    240770     7642     29843 null 1 1
    243413     7642     29844 null 1 1
    274828     7642     44849 null 1 1
    new value     8053     44849 null 1 1
    new value     8053     29843 null 1 1
    new value     8053     29844 null 1 1
    new value     8053     29728 null 1 1
    new value     8053     29727 null 1 1
    NOTE: IP_ARTICLECATEGORYACCESSID is a sequence and it should be unique
    DECLARE
    BEGIN
    MERGE INTO articlecategoryaccess b
    USING (SELECT *
    FROM articlecategoryaccess c
    WHERE nf_articlecategoryid = 7642
    MINUS
    SELECT *
    FROM articlecategoryaccess c
    WHERE nf_articlecategoryid = 8053) e
    ON (1 = 2)
    WHEN NOT MATCHED THEN
    INSERT (b.ip_articlecategoryaccessid, b.nf_articlecategoryid, b.nf_unitid, b.NF_USERID, b.N_VIEW, b.N_EDIT)
    VALUES (articlecategoryaccessid_seq.nextval, 8053, e.nf_unitid, null, 1, 1);
    END;
    i got an error after running the script:
    *Cause:    An UPDATE or INSERT statement attempted to insert a duplicate key.
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    *Action:   Either remove the unique restriction or do not insert the key.
    why would it be duplicated? its a sequence and its unique.. I dont know, maybe there is something wrong my script..
    Any help is appreciated..
    Ed

    Ed,
    1. What is the current value of the Sequence? Does the current value of sequence exist in the table? If yes, then increment the sequence to a value that is not present in the Table.
    2. Do you have any unique constraint on any of the columns that you are inserting?
    I have to ask you again, Why are you insisting on Merge statement when a simple Insert can do the job for you? Don't you feel that the below specified Merge statement is making things look more Complicated than they actually are, do you?
    Think on it and then proceed. I hope these pointers help you to resolve the issue.
    Regards,
    P.

  • Insert & Update using Writeback in a single Report

    Hi,
    Here is requirement:
    In the single report where the user has to do the Insert & update using the writeback functionality.
    below is the XMl:
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="SUBMITBUTTON">
    <XML>
    <writeBack connectionPool="CSDK">
    <insert>INSERT INTO HSCRTARGETLOOKUP(SLA_TYPE,TARGET_AVAILABILITY,TARGET_MTTR) VALUES ('@{c0}', @{c1}, @{c2})</insert>
    <update>UPDATE HSCRTARGETLOOKUP SET TARGET_AVAILABILITY = @{c1}, TARGET_MTTR = @{c2} WHERE SLA_TYPE = '@{c0}'</update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    Can you please let us know whether both insert & update will work at the same time using a single report.
    Thanks in Advance
    Siva

    Hi,
    Insert & update is working with the Single xml file:
    here it is how i have done:
    in the 1st criteria i have taken three columns and made union with the 3 dummy columns.
    in the 1st dummy column: CASE WHEN 1= 0 THEN HSCRTARGETLOOKUP.SLA_TYPE ELSE NULL END
    2nd dummy column: CAST('' AS INT)
    3rd dummy column: CAST('' AS INT)
    below is the single XML file which is working for both insert & update
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="STATES">
    <XML>
    <writeBack connectionPool="XXXX">
    <insert>INSERT INTO HSCRTARGETLOOKUP(SLA_TYPE,TARGET_AVAILABILITY,TARGET_MTTR) VALUES ('@{c0}', @{c1}, @{c2})</insert>
    <update></update>
    <update>UPDATE HSCRTARGETLOOKUP SET TARGET_AVAILABILITY = @{c1}, TARGET_MTTR = @{c2} WHERE SLA_TYPE = '@{c0}'</update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    Hope it works for you also.

  • Flash player 11.5 updated using ie8 and firefox wont work Youtube

    Flash player 11.5 updated using ie8 and firefox wont work Youtube
    Its impossible because after the update i researched and did alot to downgrade and it wont work.
    Only domain administrators can play youtube movies. the other simple users cannot play it they get a black screen please i need some clear professional instructions because its not working Youtube

    How do I fix Windows permission problems with Flash Player?
    http://forums.adobe.com/thread/987370

  • I bought the Adobe student version of Photoshop and Premiere Elements a few months ago - and now I am trying to use it, and the serial number that I have is incorrect - or it is only the registration number or something? It says I should have been sent an

    I bought the Adobe student version of Photoshop and Premiere Elements a few months ago - and now I am trying to use it, and the serial number that I have is incorrect - or it is only the registration number or something? It says I should have been sent an email with the serial number once the product was registered - But I never received this email. If anyone is able to help me with this issue - that would be great. the registration number is: PEPEP6-5578-6450-8871-9107  I am using a windows based system

    If I were you I would first make sure CS6 was deactivated or signed-out. Then download Adobe's cleaner and remove cc, CS6 and any other creative  application installed including Creative Cloud desktop application.  Then install CS6 and use your CS6  serial number during the install to activate CS6 standard or extended which ever the serial number is for.   CS6 Version 13.0 should the be activated. That level of CS6 is extremely bug ridden so be sure to the use CS6 menu Help>Updates to get CS6 updates.  Windows should update to version 13.0.1.3 Mac to version 13.0.6.  Not Subscription CS6 version 13.1.2...
    Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6

  • How to design sequence number and sub sequence number

    Hi
    I am creating DMEE for bank file, there is sequence number and sub sequence numbers in the file.
    File structure
    Aaa name 0001 tax id amount
    Bbb name 00010001 dnum amt
    Bbb name 00010002
    Bbb name 00010003
    Aaa name 0001 tax id amount
    Bbb name 00020001
    Bbb name 00020002
    Could you please help me on how to design sequence and sub sequence number in DMEE structure.
    Regards,
    Guna

    Hi,
    please find seqence number and sub sequence number in below file structure.
    Aaa name 0001(Seq. num) tax id amount   -------------------------------------header
    Bbb name 0001(Seq.num)0001(sub seq num) dnum amt---------------- item
    Bbb name 0001(Seq.num)0002 (sub seq num) ---------------- item
    Bbb name 0001(Seq. num) 0003(sub seq num) ---------------- item
    Aaa name 0001(Seq. num) tax id amount                  --header
    Bbb name 0002(Seq. num)0001(sub seq num)---------------- item
    Bbb name 0002(Seq. num)0002(sub seq num)---------------- item
    TRL
    Please help me to design sub sequence number and sequnce number again in the item details.
    Best regards,
    Anji

  • Can you create nested condition in merge(e.g. insert/update) using owb

    Hi,
    Does OWB9iR2 allow you to build in nested condition in merge. such as
    If no match on col1 and col2 then
    if col3 match then no new sequence insert <---
    else insert new sequence;
    else (there is match on col1 and col2)
    update col3 and sequence.
    I have an incremental load for a lookup table, where insert/update is used. There are two match columns and surrogate key is used. When there is no match, it shall not insert a sequence when there is a match on third column. I can not use the 3rd column in the original match because it shall be updated where there is a match for the two match column.
    I am trying to avoid using transformant for performance impact. Thanks

    HIi I think the misleading thing is that in PL/SQL you can use booleans, which is not possible in SQL. So in a PL/SQL tranformation, this is OK:
    a:= case when not orgid_lkup( INGRP1.ORG_ID )
    then get_supid(..)
    else ...
    but, the following SQL does not work:
    select case when not orgid_lkup( INGRP1.ORG_ID )
    then get_supid(..)
    else ...
    into a
    from dual;
    I ended up using only 0/1 as boolean return values for these reasons;
    so I can have:
    select
    case when orgid_lkup( INGRP1.ORG_ID ) = 0 then ...
    though true booleans are better if you don't have to embed them in SQL.
    Antonio

  • Inserted | updated | deleted | merged

    Hello,
    If a table has been set to update/insert and a row arrives with a matching column then the corresponding row in the target table is updated. In the job details window shouldnt it show a 1 under the updated section. My question really is, what does the merged tab indicate ?
    Thanks

    Hi,
    As per my knowledge
    If map runs in row based mode-- insert,update tabs are filled
    If map runs in set based mode- merge will come
    Row Based mode: In the pl/sql pkg generated by the map
    insert and update operation will happen for each row
    For insert/update option --First insert statement will run if the record exists then exception will come , then in the exception block update statment will be there and thee the record will be udpated..
    For update/insert option -- First it tries to update the record.. if it doestnt find the record it raises an exception , in the exception block insert statment will be ther
    that will insert the record..
    In Set based Mode:
    Instead of separate insert/update statements one merge stament will be there it will run...
    So set based mode is faster than row based mode..
    If any errors comes, then its difficult to find the source record causing the error in set based mode as it is in merge statment
    but it is easy in row based as it will do insert/update for each record --- each record will be inserted in the audit tables.
    Hope this will give u an idea
    Than you

  • Problem in Creating new row & inserting data using CreateInsert and Commit

    Hello All,
    I have created a page there are few input text and i want to insert the data into a database table. I have created an Application Module I am using CreateInsert and Commit operation but there is one problem.
    At first it created a row in database after that it is not creating the new row instead it is updating the same row with the new values.
    In bindings of my jspx page I have created two binding for action (1) CreateInsert for the VO of that Application Module (2) Commit operation of that Application Module.
    Here is the code snippet of my application:
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert");
    Object result = operationBinding.execute();
    *if (!operationBinding.getErrors().isEmpty()) {*
    return null;
    OperationBinding operationBinding1 = bindings.getOperationBinding("Commit");
    Object result1 = operationBinding1.execute();
    *if (!operationBinding1.getErrors().isEmpty()) {*
    return null;
    I have tried using Execute+Commit and Insert+Commit case also in every case it is updating the same row and not inserting a new row.
    Is there anything I am missing?
    Please Help.

    hi user,
    i dono. why are trying with codes. adf provides zero lines codes.
    a wonderful drag and drop functionality provide by the framework.
    while double click the button the codes are  registered in your bean
        public String cb6_action() {
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert");
            Object result = operationBinding.execute();
            if (!operationBinding.getErrors().isEmpty()) {
                return null;
            return null;
        public String cb8_action() {
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding = bindings.getOperationBinding("Commit");
            Object result = operationBinding.execute();
            if (!operationBinding.getErrors().isEmpty()) {
                return null;
            return null;
        public String cb7_action() {
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding = bindings.getOperationBinding("Delete");
            Object result = operationBinding.execute();
            if (!operationBinding.getErrors().isEmpty()) {
                return null;
            return null;
        public String cb14_action() {
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding =
                bindings.getOperationBinding("Delete4");   // some different here. after deleting usually do commit
            OperationBinding operationBinding1 =  
                bindings.getOperationBinding("Commit");    // so here commit operation.
            Object result = operationBinding.execute();
            Object result1 = operationBinding1.execute();
            if (!operationBinding.getErrors().isEmpty()) {
                return null;
            if (!operationBinding1.getErrors().isEmpty()) {
                //add error handling here
                return null;
            return null;
        }if am not understud correctly. please some more explanation need.

  • How to Create PO using ME21N and generate and IDoc for it???

    Hi All,
    Could anyone please tell me step by step process of creating purchase order and generating an IDoc for it.
    I have given all the Vendor Details, Purchase Org'n, Account Group and Company Code.
    I have given Material Details - Material Number , Quantity , Net Price, Delivery Date and Plant No.
    What step do i need to further to complete the PO and generate IDoc for it.
    Thanks
    Chinna

    Thanks Naren, Your Answer is Really Helpful.
    Now i am able to Generate the IDoc for the PO. But the Status of IDoc is 30.
    What does it mean?
    Receiver Exists, No Filters, No Interface , No Version Change.
    Why isn't my IDoc Posted ??
    It says it is ready for Dispatch.
    I'll be waiting for ur valuable replies.
    Thanks once again Naren,
    Chinna

  • How to generat sequence number for db in XSLT

    Hello SOA Gurus,
    I have a requirement, Please see below
    I am using SOA 11.1.1.6
    From a webservice call to db insert XSLT,  i have 10 elements at source side and 11 elements at target side.
    From source to target first 10 mappings are done.
    Now requirement is, for the 11th element in target- we need pass a sequence number to the targeted database, means---(sequence number has to be generated for every execution of XSLT execution)
    How to do the last point???
    Can anyone help me plzz

    Hi,
    You can pass the sequence number in the 11th element using "oraext:sequence-next-val("Sequence name as a string", "Datasource as a string") function.
    Regards,
    Anshul

  • How to get generated sequence number from JPA/TopLink

    Hi there,
    I am using JDev 10.1.3.3 with JPA + POJO + TopLink.
    In the entity (POJO), I declared a sequence generated for a number field.
    @Id
    @GeneratedValue(strategy=SEQUENCE, generator="GEN_CUSTOMER_ID_SEQ")
    @SequenceGenerator(name="GEN_CUSTOMER_ID_SEQ", sequenceName="CUSTOMER_ID_SEQ", allocationSize=1)
    @Column(name="CUSTOMER_ID", nullable = false, precision = 12 )
    private Long customerId;
    In my program, I don't need to set the Id field because it is set automatically.
    However, I want to get the generated sequence using code. Is there a way?
    Thanks,
    Jim
    P.S. I cannot use getCustomerId because the value has not been set yet.

    If you call persist on the new Entity, or flush() the id will be assigned, and you can get it.
    There is also an API on the TopLink / EclipseLink Session getNextSequenceNumberValue(), that you can use to get a sequence value.
    -- James: http://www.eclipselink.org

  • Error While Generating Sequence Number. Contact your system Administrator

    Hi All,
    I have developed a form to provide our client with 'an easy to fill' User Interface. This form will be used instead of the standard form present in Business Suite.
    Some columns of the table, on which form is based, are getting populated via generation of sequence numbers.
    Now the problem is, after deploying custom form developed by me in the instance, Standard form is showing this error
    " Error While Generating the Sequence Number. Please contact the System Administrator "
    I am unable to trace why this error had started appearing..
    Any suggestions would be of great help...
    Thanks in Advance,..

    Forms version 6i,
    Database version 9.2.0.6.0
    Sequences which I am using are used there in Standard form also..
    So evrytime i need to save the record, I am selecting NEXTVAL of it into
    the respective item of the datablock..

  • Generating Sequence Number

    Hi,
    I have created a Query form. I had displayed the sequence number of the record displayed by selecting rownum from the table.
    Now I have added a order by clause in the query. So the rownum is not displayed in the order.
    I have created a small procedure to generate the sequence number.
    I would like to know from which trigger I should call this procedure.
    procedure resequence is
    v_cursor_record number;
    v_position number;
    begin
    v_cursor_record := to_number(:system.cursor_record);
    v_position := v_cursor_record;
    loop
    :detail.item := v_position;
    v_position := v_position + 1;
    exit when :system.last_record = 'TRUE';
    Next_record;
    end loop;
    go_record(v_cursor_record);
    end;

    Thanks for your reply. I have tried this method.It assigns value only for the first record in the block. As the post query trigger is not passing the control to other items ,though more than 10 records are fetched the sequence is generated only for the first record.
    Any other method to achieve this?

  • Inserting dates using TO_DATE and getDateTime with preparedStatement

    Hi
    I have this code here but its giving error msg, *"Cannot find symbol" Symbol: method TO_DATE(...)* . Can someone point to me what is wrong??
    public static void pstmtQry(Connection con) {
    try{
      queryTable1 =" INSERT INTO Table1 "
                        + "(DATE, ID) "
                        + " VALUES (?, ?)";
      pstmtTable1 = con.prepareStatement(queryTable1);
    catch.......{
    method1() {
    try {
                pstmtTable1.setString(1,*TO_DATE*(getDateTime("dd/MM/yyyy"), "DD/MM/YYYY"));
                pstmtTable1.setString(2,ID);
    RS = pstmtTable1.executeQuery();Thanks
    Edited by: okun on Jun 9, 2010 9:02 PM
    Edited by: okun on Jun 9, 2010 9:03 PM

    Below is the query i would like to change to a preparedStatement:
    query = " INSERT INTO Table1 "
                       + "(DATE, ID) "
                     + " VALUES ( TO_DATE('"
                      + getDateTime("dd/MM/yyyy") + "','DD/MM/YYYY') "', '"
                       + ID + "')";{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for