Order not maintained in MERGE statement

I am using a MERGE statement as follows:
MERGE INTO target T
USING ( select * from source order by data_id ) S
on ( T.data_id = S.data_id )
when matched then update
set t.code = s.code
when not matched then insert
(t.code, t.data_id )
values
(S.code, S.data_id )
But the newly inserted records in the target table are not ordered in the same order as the source table.
E.g
source
data_id(pk)     code     
1     1
2     2
3     2
target
pk_col data_id     code
1     3     1
2     1     2
3     1     2
I was expecting records in noth tables to be sorted in order of data_id
Is this a limitation of merge statement or is there any workaround.

bony wrote:
I was expecting records in noth tables to be sorted in order of data_id
Is this a limitation of merge statement or is there any workaround.No, it is not a limitation. It is 101 of relational databases - there is no row order in table rows. Same query can return rows in a different order next time you run it unless ORDER BY is specified.
SY.

Similar Messages

  • Instead of trigger is NOT firing for merge statements in Oracle 10gR2

    The trigger fires fine for a update statement, but not when I use a merge statement
    with an update clause. Instead I get the normal error for the view ( which is a union all view, and therefore not updatable.)
    The error is :-
    ORA-01733: virtual column not allowed here
    oracle release is 10.2.0.2 for AIX 64L
    Is this a known bug ?
    I've used a multi-table insert statement to work around the problem for inserts, but
    for updates, I'd really like to be able to use a merge statement instead of an update.
    Mark.

    This is my cut-down version :-
    In this case case I'm getting an :-
    ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP BY, etc.
    rather then the ora-01733 error I get in the real code ( which is an update from an involved
    XML expression - cast to a table form)
    create table a ( a int primary key , b char(30) ) ;
    create table b ( a int primary key , b char(30) ) ;
    create view vw_a as
    select *
    from a
    union all
    select *
    from b ;
    ALTER VIEW vw_a ADD (
    PRIMARY KEY
    (a) DISABLE);
    DROP TRIGGER TRG_IO_U_ALL_AB;
    CREATE OR REPLACE trigger TRG_IO_U_ALL_AB
    instead of update ON vw_a
    for each row
    begin
    update a targ
    set b = :new.b
    where targ.a = :new.a
    if SQL%ROWCOUNT = 0
    then
         update b targ
         set b      = :new.b
         where targ.a = :new.a
    end if ;
    end ;
    insert into a values (1,'one');
    insert into a values (2,'two');
    insert into a values (3,'three');
    insert into b values (4,'quatre');
    insert into b values (5,'cinq');
    insert into b values (6,'six');
    commit;
    create table c as select a + 3 as a, b from a ;
    commit;
    merge into vw_a targ
    using (select * from c ) src
    on ( targ.a = src.a )
    when matched
    then update
    set targ.b = src. b
    select * from vw_a ;
    rollback ;
    update vw_a b
    set b = ( select c.b from c where b.a = c.a )
    where exists ( select c.b from c where b.a = c.a ) ;
    select * from vw_a ;
    rollback ;

  • Playlist order not maintained when synced

    I have tried all of the suggestions in the support community for syncing a playlist in the order I want. I have sorted it by the left most col and date added and when it syncs, it is always in Artist order. It is a smart playlist that takes the first song of each album I add to the Nano playlist and allows me to determine the order they appear so I can remember the newest items I added. I have done this on other iPods, but can't get it to work on the 7g Nano.
    Anybody have any ideas? I am still using iTunes 10. Don't have the nerve to upgrade to 11.
    Thanks. Brad.

    This is a bug, right?  Any chance Apple will fix this in a future firmware update? 
    This inability to match my playlist in iTunes exactly kinda makes my smart playlists worthless.  Guess I'm returning this 7G nano and going back to my 3G nano for now...

  • Merge statements in Pro*C

    First I tried doing the following:
    EXEC SQL
    MERGE INTO <table>
    ect. etc.
    And got Encountered the symbol "MERGE" when expecting one of the following:
    for, register, at, close, commit, connect, declare, describe,
    execute, fetch, open, prepare, rollback, select, whenever,
    alter, audit, comment, create, delete, drop, get, grant,
    insert, lock, noaudit, rename, revoke, set, update, validate,
    arraylen, allocate, cache, call, collection, context,
    deallocate, enable, free, lob, object, savepoint, analyze,
    explain, truncate,
    I later found out that you can't embed MERGE statements like that. So instead I tried to embed it as a PL/SQL block.
    EXEC SQL EXECUTE
    BEGIN
    MERGE INTO <table>
    USING (..)
    ON (..)
    WHEN MATCHED ..
    WHEN NOT MATCHED ..
    END;
    END-EXEC;
    And got the following: "MERGE INTO BENEFITS.BROKER_INFORMATION D
    PLS-S-00103, Encountered the symbol "INTO" when expecting one of the following:
    Does Pro*C just flat out hate merge statements?

    Hi,
    I tried out, exactly the same as you tried..
    Looks like the ANSI Pro C ompiler is not equiped to compile Merge statement.
    So if we can get the compiler not touch the Merge statement, our job is done.
    The work around is as follows:
         /*SQL Declarations*/
              EXEC SQL BEGIN DECLARE SECTION;
                        char O_str1[1024];
                        EXEC SQL VAR O_str1 IS STRING (1024);
              EXEC SQL END DECLARE SECTION;
              strcpy(O_str1,"MERGE INTO .....");
         /*SQL query to be executed*/
              EXEC SQL PREPARE curSqlStmt FROM :O_str1;
    Please try and respond, it worked for me...
    Regds
    Santosh Iyengar

  • Profit Center was not maintained during order n billing creation.

    Dear, Gurus
    I'm facing a problem of Profit Center. User created a service material, maintenance contract. They created a Billing Document as it is order related billing. Accounting document was not generated when saving invoice. When I got to the bottom of this I realized no costing tabs were ever maintained for material type services. (Henceforth no Profit Center in Sales Order n Invoice).
    I have done the necessary config n assignments but question now is what should I do as in billing doc  the field is greyed out it will not allow me to assign Pr Center now. I am thinking that this may work if I cancel the billing document and then go back to sales order and try and changing the field, then re-create the invoice. I'm trying to avoid canceling. Is there any program, bapi, user exit I may use to re assign or make system re check the MM while saving invoice to allow accounting document to be created?  This is one scenario.
    2nd scenario is similar but in the case of this contract everything was made. Accounting document was cleared even but with some dummy weird Profit Center. (No proft center in Order nor invoice.) Whole problem at first in this scenario is User saying everything is complete so status in doc flow should show maintenance contract as complete but wasn't. it showed being processed. I discovered no completion rule was maintained. I maintained E Full target value referenced but status still has not changed any idea guys? (New config not showing on old existing data only show on new document, concept?) Is there a program or anything to make system update status doc flow? aside from this Profit center  incompletion log is coming in Contract. Not maintained in order or invoice.

    In one of my earlier projects, a similar requirement was putforth by users and we had developed a zee tcode to change the profit center in billing document via SM30 which can be done only by FI authorised users.
    I am reproducing the said program as under:-
    REPORT  "ZPROFIT_CHG"
    TABLES : VBRP.
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME.
    SELECT-OPTIONS : SO_VBELN FOR VBRP-VBELN OBLIGATORY.
    PARAMETERS:      P_PRO LIKE VBRP-PRCTR OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK B1.
    DATA : BEGIN OF IT_VBRP OCCURS 0,
            VBELN LIKE VBRP-VBELN,
            POSNR LIKE VBRP-POSNR,
            PRCTR LIKE VBRP-PRCTR,
          END OF IT_VBRP.
    DATA COUNT(3).
    DATA W_MESSAGE(30).
    START-OF-SELECTION.
      LOOP AT SO_VBELN.
           IF SO_VBELN-LOW CA '~`!@#$%^&*()_+|\=-><,.;":' OR SO_VBELN-HIGH CA '~`!@#$%^&*()_+|\=-><,.;":'.
               MESSAGE 'Special character not allowed' type 'S'.
               LEAVE LIST-PROCESSING.
               STOP.
           ENDIF.
      ENDLOOP.
      IF P_PRO CA '~`!@#$%^&*()_+|\=-><,.;":'.
               MESSAGE 'Special character not allowed' type 'S'.
               LEAVE LIST-PROCESSING.
               STOP.
      ENDIF.
      SELECT B~VBELN B~POSNR B~PRCTR FROM VBRK AS A  INNER JOIN VBRP AS B ON A~VBELN EQ B~VBELN INTO CORRESPONDING FIELDS OF TABLE IT_VBRP
                                WHERE A~VBELN IN SO_VBELN
                                AND   A~FKART EQ 'ZFF2'
                                AND   A~FKSTO NE 'X'.
      IF SY-DBCNT EQ 0.
          MESSAGE 'NO DATA FOUND' TYPE 'S'.
          LEAVE LIST-PROCESSING.
      ENDIF.
      SORT IT_VBRP BY VBELN.
      DELETE ADJACENT DUPLICATES FROM IT_VBRP COMPARING VBELN.
      CLEAR COUNT.
      IF IT_VBRP[] IS NOT INITIAL AND P_PRO IS NOT INITIAL..
          LOOP AT IT_VBRP.
              UPDATE VBRP SET PRCTR = P_PRO  WHERE VBELN = IT_VBRP-VBELN AND POSNR = IT_VBRP-POSNR.
              IF SY-SUBRC = 0.
                 COUNT = COUNT + 1.
              ENDIF.
              COMMIT WORK.
              CLEAR IT_VBRP.
          ENDLOOP.
    ENDIF.
    IF COUNT IS NOT INITIAL.
        CONCATENATE 'No Of Records Updated Is - ' COUNT INTO W_MESSAGE.
        MESSAGE I000(ZSFL) WITH W_MESSAGE.
    ELSE.
        MESSAGE 'No Records Updated' TYPE 'S'.
    ENDIF.
    Since I am so weak in ABAP coding, not sure whether the above coding is correct.  You need to check with your ABAPers and develop this logic.  This should work.
    thanks
    G. Lakshmipathi

  • FORALL MERGE statement works in local database but not over database link

    Given "list", a collection of NUMBER's, the following FORALL ... MERGE statement should copy the appropriate data if the record specified by the list exists on both databases.
    forall i in 1..list.count
    merge into tbl@remote t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    But this does not work. No exceptions, but target table's record is unchanged and "sql%rowcount" is 0.
    If the target table is in the local database, the exact same statement works:
    forall i in 1..list.count
    merge into tbl2 t
    using (select * from tbl
    where id = list(i)) s
    on (s.id = t.id)
    when matched then
    update set
    t.status = s.status
    when not matched then
    insert (id, status)
    values (s.id, s.status);
    Does anyone have a clue why this may be a problem?
    Both databases are on Oracle 10g.
    Edited by: user652538 on 2009. 6. 12 오전 11:29
    Edited by: user652538 on 2009. 6. 12 오전 11:31
    Edited by: user652538 on 2009. 6. 12 오전 11:45

    Should throw an error in my opinion. The underlying reason for not working is basically because of
    SQL> merge into   t@remote t1
         using   (    select   sys.odcinumberlist (1) from dual) t2
            on   (1 = 1)
    when matched
    then
       update set i = 1
    Error at line 4
    ORA-22804: remote operations not permitted on object tables or user-defined type columnsSame reason as e.g.
    insert into t@remote select * from table(sys.odcinumberlist(1,2,3))doesn't work.

  • IW32: Error getting message (Text for order header not maintain in lang.EN

    Hello All,
    We just starting getting this message in IW32 and IW33 stating (Text for order header not maintained in language EN) then all the pre-existing description test disappeared.
    We have not done any configuration change in this particular system.
    Can anyone help to resolve this.
    Thanks

    Hi,
    As with most SAP messages it is always a good idea to trust what it is saying.
    The system is telling you that KG has not been created in the English language.
    Go to transaction CUNI to check the settings.
    Select the Unit of measure for "MASS" (from the drop down list) and check the entries for UOMs.
    KG should be there and should have an English description (the message said it was not there for EN)
    If it is there and set up correctly then there might have been something else in the UOM field? You didn't enter " KG" did you (a blank character then  KG?)
    Steve B

  • Problem in merge statement -ORA-27432 Step does not exist for chain

    Hi
    I m getting ORA-27432 Step does not exist for chain error in merge statement.Please explain the same.
    MERGE INTO fos.pe_td_hdr_sd B
    USING (
             SELECT ACTIVE, ADDUID, ADDUIDTIME,TDKEY         FROM pe.pe_td_hdr
              WHERE  (adduidtime like '20070104%' or edituidtime like '20070104%')
              AND NVL(legacy_td,'N')<>'Y'
              AND SUBSTR(adduidtime,1,4)='2007'
              AND AMENDMENT_NO=0)A ON ( B.TDKEY = A.TDKEY)
      WHEN MATCHED THEN
        UPDATE SET B.ACTIVE=A.ACTIVE,
    B.ADDUID=A.ADDUID,
            B.ADDUIDTIME=A.ADDUIDTIME
      WHEN NOT MATCHED THEN
                      INSERT
                              B.ACTIVE,
                              B.ADDUID,
                              B.ADDUIDTIME)
                        VALUES(
                              A.ACTIVE,
                              A.ADDUID,
                              A.ADDUIDTIME)This query is a short version of the main query.It is same but having 180 columns in original table.

    What version of Oracle are you using? This message does not appear in my 10.1 Error Messages document, but the other messages in that range seem to be about DBMS_SCHEDULER.
    Are you using scheduler somewhere around where you are getting the error message?
    John

  • In IPhoto 11 I have made an album and rearrange the photos in the order I require them. When export the album to allow me to burn them to disk to be viewed in Windows they do not maintain the same order. What am I doing wrong?

    In IPhoto 11 I have made an album and rearrange the photosin the order I require them. When export the album to allow me to burn them todisk to be viewed in Windows they do not maintain the same order. What am I doingwrong?

    When you sort the Album in iphoto are you sorting manually? Or by date of the photos?
    When you sort in the Finder how are are you sorting?
    Here's one way to do what you're trying to do:
    Create your Album and sort the pics as you want them. Then Photos Menu: Batch Change -> Set Title to Text "John's Birthday", for instance, and tick the box to append a number to each Photo. Now your photos are titled 'John's Birthday 001, John's Birthday 002 ... etc'
    Then File -> Export and in the Export dialogue set the Filename to "Use Title"
    Sort on Filename in the Finder and you end up with a folder full of images in the same order as the Album in iPhoto.
    Regards
    TD

  • Oracle 11g merge statement not working properly

    HI I have recently my oracle version to 11.2.0.3 -64 bit . My merge statement is geeting failied saying that invlid identfier at line number 18    
    MERGE INTO peer_index indx        USING staging.stg_peer_filing stg          ON (indx.peer_element_code = stg.fund_code                and indx.index_effective_date = trunc(stg.pricing_date))        WHEN MATCHED THEN UPDATE          SET indx.filing_date = trunc(stg.filing_date),            indx.reported_net_assets = stg.net_assets,            indx.active_flag = 'N',            indx.parent_index_code = NULL,            indx.update_datetime = systimestamp,            indx.last_update_user_id = user        WHEN NOT MATCHED THEN INSERT         (index_code, peer_element_code, filing_date, index_effective_date,          reported_net_assets, active_flag          )        VALUES         ((SELECT pe.index_code_prefix || to_char(stg.pricing_date,'MMRR')           FROM fi_benchmark.peer_element pe           WHERE pe.peer_element_code = stg.fund_code),          stg.fund_code, trunc(stg.filing_date), trunc(stg.pricing_date),          stg.net_assets, 'N'         );
    please help why this is happening .Same query works fine in 10g .

    which line is the line that has the error?
    merge INTO peer_index indx
    USING staging.stg_peer_filing stg
    ON (indx.peer_element_code = stg.fund_code AND indx.index_effective_date = Trunc
    (stg.pricing_date))
    WHEN matched THEN
      UPDATE SET indx.filing_date = Trunc(stg.filing_date),
                 indx.reported_net_assets = stg.net_assets,
                 indx.active_flag = 'N',
                 indx.parent_index_code = NULL,
                 indx.update_datetime = systimestamp,
                 indx.last_update_user_id = USER
    WHEN NOT matched THEN
      INSERT (index_code,
              peer_element_code,
              filing_date,
              index_effective_date,
              reported_net_assets,
              active_flag )
      VALUES ((SELECT pe.index_code_prefix
                      || To_char(stg.pricing_date, 'MMRR')
               FROM   fi_benchmark.peer_element pe
               WHERE  pe.peer_element_code = stg.fund_code),
              stg.fund_code,
              Trunc(stg.filing_date),
              Trunc(stg.pricing_date),
              stg.net_assets,
              'N' );

  • Merge statement not working over db link

    I have a merge statement that works fine when it's run against a local table, but when I try to run it against a table over a database link, I get the following error.
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-02063: preceding line from REPOS
    ORA-06512: at "DBADMIN.PING_DB", line 6
    ORA-06512: at line 1
    Here is the code:
    create or replace procedure ping_db
    as
    begin
    merge into availability@repos A
    using (select trunc(sysdate) from dual)
    on (trunc(A.day) = trunc(sysdate))
    when matched then update set A.uptime = A.uptime + 1
    when not matched then insert (hostname,dbname,day,uptime) values
    (utl_inaddr.get_host_name,sys.database_name,trunc(sysdate),1);
    commit;
    end;
    /Code compiles fine, but gets the error when it's executed. Any help would be appreciated.

    9.2.0.x is the version (9.2.0.4,.5 and .6)

  • Close shop order Fiscal year variant B2 is not maintained for calendar year

    Hello,
    I know there are already some threads in the forum about this error, but I could not find an answer that works for me.
    Here is the scenario:
    We do want to close a production order in CO02. (CO02-functions-restrict processing-close).
    I get an error message u201CUnprocessed future change recs for order xxprevent del. flag/completionu201D
    Message no. CO688
    Transaction COFC shows me 6 errors (all the same) for this production order, I guess this might be the reason for the previous error:
    u201CFiscal year variant B2 is not maintained for calendar year 2006u201D
    When I now go into OB29, it shows entries for B2 for the year 2006, it has 12 periods, so it looks fine for me.
    Any suggestions?
    Thanks
    Anne

    - check out this note
    https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=487683
    Note 487683 - CO688 for 'complete technically' or set deletion flag
    Symptom
    An order should be technically completed or the deletion flag should be activated for the order.
    The action cannot be carried out since the system issues error message CO688 "Unprocessed future change recs for order & prevent deletion flag/completion".
    Even after you have started report CORUPROC for processing the unprocessed future change records, the action cannot be carried out.
    Other terms
    Archiving, complete technically,
    LÖVM, TABG, CO688, CO 688
    Reason and Prerequisites
    The action cannot be carried out since there are incorrect goods movements or incorrect actual costs for the order.However, this option is not mentioned in the long text of message CO688.
    Solution
    With the aid of Transactions COGI and COFC, you must check whether there are incorrect goods movements or incorrect actual costs for the order and you must post-process them.
    You can change the long text of the message as follows by using Transaction SE91 in order to add missing information:
    Diagnosis
    For the order, you must still process future change records or error records from the confirmation for confirmation processes.These are the possible confirmation processes:
    automatic goods receipt
    backflush
    actual cost determination
    data transfer to HR
    System activities
    For orders with confirmation processes to be post-processed, setting of the deletion flag or of status 'completed' has not been planned.
    Procedure
    You must process the unprocessed future change records with the help of
    predefined confirmation processes</> or
    with the aid of program CORUPROC, when you dispatch it in Customizing in a background job (dispatch background jobs: confirmation processes).
    You must check whether there are incorrect goods movements or incorrect actual cost determination for the order and you might have to post-process them:
    post-processing of incorrect goods movements</>
    post-processing of incorrect actual cost determinations</>

  • Bean State is not maintained in producer

    Hi,
    In my application, whenever we click on the 'Add' button, document is added to bean and page is submited again and the same apge is displayed. For e.g, I have employeeDetails.xhtml apge and whenver I add any document, document is added to Bean, and employeeDetails.xhtml page is shown again. but now in portal, employeeDetails apge after adding docuemnt is throwing exception. the reason which we found out is that, bean state is not meintained and due to which RenderRequest reinitializes the bean and all saved data is lost.
    Can you pelase help on this?

    In Create Mode od material Master: MM01 Enter the material code & enter the same in Reference material & enter. In the next step select Purchasing, as it refers to not have maintained & enter Organization data & enter. Now maintain Purchasing Tab page.
    This process in SAP is known as Extending Material Master.  You can extend the material master for adding Views not maintained, also for extending material to another plant or combination of Sales Org & Distribution Channel, & so on ...
    Hope this resolves your issue.
    Regards,
    Rajesh Banka

  • Layer palette not maintaining state, what to do??

    Problem: Layer palette chages state between the closing and reopening of a file.
    What I would like to be able to do is open a .ai file and have the layer palette exactly the way the way I left it when I closed the file. Currently upon reopening a file many of the layers will be fully expanded and I have to go through and collapse them all.
    Is there a way to force Illustrator to maintain layer palette state between file sessions?
    Thanks.

    The behaviour - or the issue - has been introduced in Illustrator 9, the first version which included nested layers. The behaviour has been legitimately criticised pretty often.
    However, if you want to collapse/expand all layers in one step you might consider converting your main layers into sublayers. That is:
    • Create a new 'master layer' on top of the entire stack of main layers
    • Drag all main layers onto the master layer in order to make them sub layers of the master layer
    • Now you can Alt/Option Click the triangle on the left-hand side of the master layer in order to collapse or expand all sublayers
    Of course, this way is only applicable if using sublayers is an option for you.

  • Hierarchy and order of albums is not maintained when sharing libraries

    Hi - I'd like to share photos on my computer with those stored on my wife's computer and vice versa. I enabled the "share entire library" options and we both can see each others libraries. So far so good, however, the hierarchy of the how the photos are organised within each library is not maintained.
    For example, I have organised my photos into folders containing albums and smart albums. There are also some albums and smart albums at the top level alongside the folders. When my wife accesses my library from her machine she can only see the top level entries and they appear in what seems to be random order.
    Is there a way to maintain the order and hierarchy across shared libraries?
    BTW, I also tried it with the "share selected albums" option but again I can only see the top level folders and albums and I don't want to have to manually add items to the share whenever I create a new folder or album.
    Cheers
    Michael

    Afraid not.
    iPhoto menu -> Provide iPhoto Feedback for feature requests.
    Regards
    TD

Maybe you are looking for