Insert as per sort by statement given

In below given example, the data does not get inserted as per the sorting given i.e ORDER BY c002,c003
Kindly suggest the solution..
Sanjay
BEGIN
MERGE INTO my_table a
  USING (
     SELECT seq_id,
          c001, -- Holding primary key
          c002,
          c003,
          c004,
          c005
     FROM apex_collections
     WHERE collection_name = 'MY_COLLECTION'  ORDER BY c002,c003
     ) b
    ON (a.tbl_col1 = b.c001)
  WHEN NOT MATCHED THEN
    INSERT (a.tbl_col2, a.tbl_col3, a.tbl_col4, a.tbl_col5)
    VALUES (b.c002, b.c003, b.c004, b.c005);
END;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

user12957777 wrote:
In below given example, the data does not get inserted as per the sorting given i.e ORDER BY c002,c003
Kindly suggest the solution..
Sanjay
BEGIN
MERGE INTO my_table a
USING (
     SELECT seq_id,
          c001, -- Holding primary key
          c002,
          c003,
          c004,
          c005
     FROM apex_collections
     WHERE collection_name = 'MY_COLLECTION'  ORDER BY c002,c003
     ) b
ON (a.tbl_col1 = b.c001)
WHEN NOT MATCHED THEN
INSERT (a.tbl_col2, a.tbl_col3, a.tbl_col4, a.tbl_col5)
VALUES (b.c002, b.c003, b.c004, b.c005);
END;The USING clause provides a set of data to the MERGE statement. Just because you order that set of data inside the USING clause doesn't mean that it causes the MERGE statement to insert data in that order.
Your ordered set of data (b) is being joined to your merging table my_table, to determine what matches and what doesn't. At that point the ordering is irrelevant, because the optimizer will join the data for the merge statement in the best way it can.
As others have said, it doesn't matter what order your data is inserted.

Similar Messages

  • Display number of entries per sort order

    G'day all.
    Does anybody know how I can display number of entries per sort order in
    ALV grid.
    i.e. ABC 2000
    2000
    2000
    3 (entries) 6000
    DEF 1000
    HIJ 2000
    2 (Entries) 3000
    5 (Total Entries) 9000

    Hi,
    The way I did it I used "AT END OF " statement and added my amount to a
    variable and then move my variable in work area and then modified your
    internal table from work area transporting that field or depending on
    your requirement that you need to add a separate line for totals append
    the internal table which you are going to use it for first display. Then
    after the set_table_for_first_display I added the alv_build_sort
    criteria. And call method alv_list->set_sort_criteria exporting the
    internal table i_sort.
    Cheers,
    Chaitanya

  • Does an iphone4s become locked to the SIM card that you insert after you follow the steps given to unlock the phone? Thanks a mill

    Does an iphone4s become locked to the SIM card that you insert after you follow the steps given to unlock the phone?
    I just received the steps by email from meteor and I'm moving to OZ in September. I have the OZ SIM card I intend using over there but I don't want to end up locking the whole phone to the OZ network before I go there.
    Any help on this matter would be greatly appreciated

    That only happens when you purchase a supposedly unlocked phone from specific stores that say their unlocked but as soon as you insert a sim card they lock to that carrier... a trick (sort of)... that's something totally different than what you are about to do!

  • INSERT Script stored as "SQL Statement Script" not firing on Oracle Alert

    We are using Alert Manager to run Alerts based on absence information in EBS R12.1.3 HR tables.
    Application: Human Resources
    Period/Event: Periodic
    Frequency: Every Day
    The Alert has 2 actions.
    One is to email a supervisor based on the Alert SQL finding staff who have had x number of absences over a set period of time.
    That is working fine.
    The other action is defined as an "SQL Statement Script".
    The SQL script inserts the variables defined in the SQL from the main Alert definition SQL, into a custom table.
    When the Alert fires, we are getting the email generated, but the INSERT statement isn't firing.
    However, when we look at the result of the Alert when it has run, and look at the steps which were fired, we can see the email step and the SQL step. When we look at the SQL in the SQL step which was generated, we can copy and paste it direct into TOAD and it works fine.
    We have tried a simple SQL INSERT statement which even just does:
    INSERT INTO xx_tmp (VALUE1_DATE, VALUE2) VALUES (SYSDATE, 'this');
    But even that does not work.
    We wonder if the issue is that we cannot do a direct INSERT from an alert type of "SQL Statement Script"?
    We have found another Alert which does a direct UPDATE on a table, but the SQL Statement Script definition has "Purchasing" as the Application, because it's updating a PO table.
    In our case, we're trying to insert into a custom table held in our in-house XX schema.
    Could the problem be that we don't have the "Application" set? If that's the case, we don't have a corresponding application anyway.
    Or can we not do a direct INSERT like this - do we need to use a package instead, and call that?
    Any advice much appreciated.
    Thanks

    Hi Brian,
    Alert issue - Custom SQL fix
    1. Define actions via "Actions" button on Alert Definition
    2. Create an action for e.g. "Send Message to Supervisor"
       Action type: message
       Action - sends email to people
    3. Create another action called e.g. "Insert Record"
       Action type: SQL Statement Script
       Fill in SQL in the "Text" section, no need to add a begin or end bit, just a simple INSERT INTO X etc ending with a semi colon
    4. Back on the main alert definition window, go to "Action Sets" button
       Here, need one SEQ for the Message / Email (e.g. Seq 1), and then click on "Action Set Details" and click on "Members" tab and select the "Send Message to Supervisor" Action
       Then close the "Action Set Details" window, and return to the "Action Sets" window
       click into 2nd line, add e.g. Seq 2, and call it e.g. "Insert Record", click on "Action Set Details" > Members tab and select the "Insert Record" The problem was that in the first instance, we had a single Action Set, and under "Members" had selected the "Send Message to Supervisor" and "Insert Record" at the same time.
    Short answer: each Action needs to be defined as a separate line in the Action Sets definition.
    I can send screenshots if you need them, and don't mind putting your email address on this forum.
    You can always edit the thread after I've emailed you, to remove your email address.

  • Hello,  I am trying to insert a variable into php statement.

    Hello, I am trying to insert a variable into this statement.
    Variable name is $stable
    <?php echo 'includes/   $stable  .php ';?>

    The above concatenation is my preferred method but the easiest to read is to use double quotes and curly braces:
    <?php echo "includes/{$stable}.php"; ?>
    There is a slight performance hit this way but on a small project it shouldn't make any difference.

  • Insert and select in one statement

    using MS Sql server and VB i can execute two queries Insert and select in one statement e.g. (insert into (....) values (...) Select @@Identity).
    how can i do the same thing using Oracle and VB. ???
    It gives error. here's what i want to do.
    (insert into table1 (...) values (...) Select table1_sequence.currval from dual )
    Khurram

    Here's how you can achieve the same Oracle :-
    Test Db>desc tmp1;
    Name Null? Type
    EMP_NO VARCHAR2(10)
    EID NUMBER
    Test Db>insert into tmp1 (emp_no, eid)
    2 select '123', 1
    3 from dual;
    1 row created.
    Shailender Mehta

  • How to insert record in sorted table

    Hi,
    Please tell me how to inser the record in the sorted internal table. This is the code which is not working properly. just tell me what r the changes need to b done.
    Thanks,(reward points for sure)
    DATA: BEGIN OF connection,
            cityfrom TYPE spfli-cityfrom,
            cityto   TYPE spfli-cityto,
            distid   TYPE spfli-distid,
            distance TYPE spfli-distance,
          END OF connection.
    DATA connection_tab LIKE sorted TABLE OF connection
                        WITH  KEY cityfrom
                                     with header line.
    SELECT cityfrom cityto distid distance
           FROM spfli
           INTO connection.
      INSERT connection INTO connection_tab.
    ENDSELECT.
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.
    connection-cityfrom = 'Bangalore'.
    connection-cityto = 'Delhi'.
    connection-cityfrom = 'KL'.
    connection-cityfrom = '2500'.
    insert connection to  connection_tab .
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.

    Hi,
    sorry that's by mistake.. but  i m getting runtime error if i insert record into sorted table
    DATA: BEGIN OF connection,
    cityfrom TYPE spfli-cityfrom,
    cityto TYPE spfli-cityto,
    distid TYPE spfli-distid,
    distance TYPE spfli-distance,
    END OF connection.
    DATA connection_tab LIKE sorted TABLE OF connection
    WITH  unique KEY cityfrom
    with header line.
    SELECT cityfrom cityto distid distance
    FROM spfli
    INTO connection.
    INSERT connection INTO connection_tab.
    ENDSELECT.
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.
    connection-cityfrom = 'Bangalore'.
    connection-cityto = 'Delhi'.
    connection-distid = 'KL'.
    connection-distance = '2500'.
    insert connection into table connection_tab .
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.

  • Sort remuneration statement (report RPCEDTP0)

    Dear gurus,
    I need to find an exit for report RPCEDTP0, because a need to sort the remuneration statement by name and last name.
    The standard button SORT ORDER from report RPCEDTP0 is not giving me what I need...
    Does anyone know something that may help me?
    Thank you in advance,
    PC

    Hi Ted Dinh!
    Your advice seemed to be such a good one... but I'm not having success
    I created an enhancement in form 'FILL_SORT_CONDITION_TABS' ( include: 'LRPPNTOC') and inserted this code inside it:
      SORTORDERS-FIELDNAME = 'ENAME'.
      SORTORDERS-POSITION = '26'.
      APPEND SORTORDERS.
    But when I click on button 'SORT ORDER'... I don't see any difference..
    Do you have some idea of what can be happening?
    Regards,
    Priscila

  • How to insert a table with ref statement?

    the script:
    CREATE OR REPLACE TYPE B_T AS OBJECT (
    type varchar(6),
    value number(2));
    create table Bo of B_T;
    insert into Bo values('a',0);
    insert into Bo values('b',1);
    create or replace type try_T AS OBJECT(
    iii number(10),
    aaa ref B_T);
    create table try of try_T
    (scope for (aaa) is Bo);
    how to insert into the "try" table?
    the statement:
    insert into try values(4,B_T('a'))
    or :
    insert into try values(4, ref(t) from bo t where bo.type='a');
    both are erro.
    help me please.

    Hi,
    Right click the mouse->create->table
    If you want 5 columns, you need to declare 5 cells in one line type of the table
    Click on Table -> Details, then do the following
    Line Type 1 2 3 4 5
    L1 2mm 3mm etc
    Here specify the width of the columns as many as you want..
    then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there.

  • How to insert variable value using select statement - Oracle function

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this.
    thanks

    Hi,
    I have a function which inserts record on basis of some condition
    INSERT INTO Case
    Case_ID,
    Case_Status,
    Closure_Code,
    Closure_Date
    SELECT newCaseID,
    caseStatus,
    Closure_Code,
    Closure_Date,
    FROM Case
    WHERE Case_ID = caseID
    Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
    how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
    Regards.

  • How to insert ORACLE HINT into select statement....

    Hi team,
    Can you please suggest me how to add an Oracle hint to point the Program to BSAD~1.
    Index BSAD1 has all three fields MANDT, BUKRS, AUGDT which are there in the where clause. But as per the execution plan index BSAD0 is being used which is the primary one.
    Also the stats for this table are are current.
    Thanks in Advance.
    Puneet.

    Hi punnet, look at this example:
      SELECT MAX( kkop~augbd )
      INTO it_gen_docs-augbd
      FROM ( fkkvkp AS vkp INNER JOIN dfkkop AS kkop
         ON vkpvkont = kkopvkont ) INNER JOIN dfkkko AS kkko
         ON kkopaugbl = kkkoopbel
      WHERE vkp~exvko = ti_cuentas-exvko
            AND kkop~bukrs = p_bukrs
            AND kkop~blart IN r_blart
            AND kkop~augst = '9'
            AND kkko~blart IN r_blartd
    %_HINTS ORACLE 'INDEX("DFKKOP" "DFKKOP~Z07")'.
    DFKKOP is the table name and DFKKOP~Z07 is the index.
    I hope this helps you.

  • Monitor/trace per transaction performance stats

    Is it possible to trace stats like cpu time and num of IOs for each committed transaction and log them one row per transaction? Thanks, Stan

    Yes it is possible through statspack which give you all other performance related information. But it is also very resource consuming job. so be carefull while using it.

  • How sort projects by given number serie (ie. date)

    Hi,
    Right or wrong my 35 000 photos are in the library put in folders by year. Within each year there are projects (approx 30 -70 per year) with project names such as "20100725 closeups of a moose". When i add new projects as days go by and name them by the date series I use, they do not automatically drop into a slot as they would if sorted by the number.
    How do I sort projects by their name (ie number series)?
    please advice,
    regards pyry.

    Hi
    Right click or control click on a year folder, go down to Keep Arranged By, choose Kind, Name or Manual
    gary

  • Insert into some sort of temp table?

    Hi there,
    Not sure how to do this, I have three Two CTEs
    with a as (select field1, field2, field3 from table1),
    b as (select field1, field2, field3 from table2)
    Now I would like to insert each result from the above CTE into some kind of table or something. I would not want to use a temp table cause I read that's not a good approach. I'm kind of new to the Oracle world. I'm coming from a SQL server background and the way I would do it in SQL server would something like creating a Table variable and inserting all the result sets into that table variable, hence avoiding the creation of a temp table with in Oracle its more like a permanent table I read.
    Let me know what would be the best approach to accomplish this task here.
    Thanks very much for your help.

    Hi,
    Sorry, I don't understand what you want.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
    Always say which version of Oracle you're using.
    Midway wrote:
    Hi there,
    Not sure how to do this, I have three Two CTEs
    with a as (select field1, field2, field3 from table1),
    b as (select field1, field2, field3 from table2)Why do you need CTEs? Why can't you just use table1 and table2?
    Now I would like to insert each result from the above CTE into some kind of table or something. I would not want to use a temp table cause I read that's not a good approach. I'm kind of new to the Oracle world. I'm coming from a SQL server background and the way I would do it in SQL server would something like creating a Table variable and inserting all the result sets into that table variable, hence avoiding the creation of a temp table with in Oracle its more like a permanent table I read.
    Let me know what would be the best approach to accomplish this task here.What is the task that you want to accomplish?
    Is INSERTing really the goal, or is that a means you might use to accomplish your real task?
    If all you want to do is generate a specific output, then I'm sure you don't need any other tables, temporary or otherwise. Exactly how to do it depends on what data is in your actual tables, and what results you want from that data. As long as I don't know where you're starting from, or where you want to go, I can't give you very good directions.

  • Doing an insert and update in one statement.

    Hypothetical Situation:
    I have a table, this table has let say five rows and several thousand records. I want to take all the records where I take two of those rows with certain values in them, then duplicate those records that match the criteria and reinsert them onto the table. Afterwards, I want to change the same two values that I originally used to search for those records on the newly made duplicates and update the table to reflect the new changes.
    To Illistrate:
    Table Test:
    Rows:
    First Name
    Last Name
    Earnings
    Employment Date
    Rating
    Say I am looking for all records with earnings of 30,000 and a rating of B....duplicate those records and readd them to the table, then change the earnings of the duplicates to 40,000 and the rating to A.
    Any suggestions on how to approach this in as few of statements as possible (preferrably one statement)?
    Thanks In Advance.

    yep I ment columns, sorry for the confusion.
    Slightly straying now on this topic....After evaluation of what I needed, I'd come to the conclusion that my work would actually need something along the lines of an INSERT ALL or INSERT FIRST (TY Eric for putting me on the right track btw).
    Basically I'm going to need to do multiple value inserts into one statement, thus why this looks to be the right direction. So I typed it up, made sure it was fine and tried it....
    .....only one problem, ALL and FIRST are new to 9i....and I'm using 8.1.....doh >_<
    So, is there something simular to an INSERT ALL or INSERT FIRST that predates it that I can use in 8.1 and get the same effect (i.e. multiple insert changes in one statement)?
    Thanks again.

Maybe you are looking for

  • HT4914 i subscribed to itunes match and i can't get it to come up on my apple ipad mini....help

    I subscribed to apple itunes match and for some reason it won't load onto my ipad.  Do anyone know how to get it to download

  • Business area wise Automatic Payment program run

    Dear all clarifications regarding Automatic Payment Program vs Business Area,  They want to run Automatic Payment Program  run Business Area wise They want to run payment run with reference of business area for example 1) BUSINESS AREA : A 2) BUSINES

  • Problems selecting paper bin/source with some printers drivers

    Hi, I'm using CR2008 SP2 .NET SDK. With some printers drivers i'm unable to set the correct paper source in the print options. For example, if I use Toshiba e-series PLC driver (you can find it here:drivers and select, for example, the e-STUDIO281C p

  • Problem with ValueChangeEvent vs. ActionEvent in JSP / ADF

    Hi all, I have an Oracle map viewer app in which I have a SelectOneChoice control for the user to pick the name of the place to map. I tried setting a value change listener on the control. This called the right Java method on my backing bean & did th

  • FLV File to DVD

    Hi, I have a number of video files in FLV format. I have an iBook G4 with Mac Os X I would like to collate them all, putting them on a dvd, with a central menu which gives the user the option to choose which one to watch! How do I do this! I have bot