Re: Update Duplicate Rows

Oracle 11.2.0.2
Windows 2008
I have this table (case_file) with duplicate rows (case_number).
I will like to make the case_number unique through out the table.
For example, if I have two rows with the same case_number(225), I will like to change one of the numbers and record that case_number to the privious_case_number column.
I am looking for a way to write up a script to automate the process.
Any help will be appreciated.
CREATE sequence case_id_seq
start with 25;
create table case_file
( case_id number not null, case_number varchar2(25), privious_case_number varchar(25), modified_by varchar2(50));
INSERT into case_file (case_id, case_number, privious_case_number, modified_by)
VALUES (case_id_seq.nextval, '220', '2002', 'DBA');
INSERT into case_file (case_id, case_number, privious_case_number, modified_by)
VALUES (case_id_seq.nextval, '225', null, 'DBA');
INSERT into case_file (case_id, case_number, privious_case_number, modified_by)
VALUES (case_id_seq.nextval, '224', null, 'PM');
INSERT into case_file (case_id, case_number, privious_case_number, modified_by)
VALUES (case_id_seq.nextval, '205', null, 'Supervisor');
INSERT into case_file (case_id, case_number, privious_case_number, modified_by)
VALUES (case_id_seq.nextval, '225', null, 'DBA');When I run the below query, I get this result, with 225 showing up twice:
select * from case_file;
26     225     2002     DBA
27     220     2002     DBA
28     225          DBA
29     224          PM
30     205          Supervisor
31     225          DBAWhen I run the below script:
SELECT case_number, COUNT(case_number) as Number_Of_Case_Number
FROM case_file
GROUP BY case_number
HAVING COUNT(case_number) > 1I get this result
CASE_NUMBER NUMBER_OF_CASE_NUMBER
225 3
SQL>Edited by: 868332 on Feb 6, 2012 1:23 PM

Hi,
Do you really need two unique numbers for each row?
To make case_numebr unique, first, see what the highest existing case_number is, and create a new sequence that starts after that point:
CREATE SEQUENCE     case_number_seq
START WITH     250;Always use that sequence when assigning case_numbers in the future.
To re-number the existing duplicates :
UPDATE     case_file
SET     case_number          = case_number_seq.NEXTVAL
,     previous_case_number     = case_number
WHERE     case_id         IN (
                     WITH  got_r_num     AS
                      SELECT  case_id
                      ,       ROW_NUMBER () OVER ( PARTITION BY  case_number
                                                          ORDER BY         case_id
                                     )  AS r_num
                      FROM    case_file
                  SELECT  case_id
                  FROM        got_r_num
                  WHERE   r_num     > 1
;The sub-query got_r_num assigns numbers 1, 2, 3, ... to all rows, in order by case_id (lowest case_id gets r_num=1) with a separate set of numebrs for each case_number. When there are duplicates, one of the rows with that case_number will keep that case_number, and all the others will be new case_numebrs from case_numebr_seq.
Edited by: Frank Kulash on Feb 6, 2012 4:37 PM
Originally missed the part about previous_case_number. (Be careful how to spell "previous".)

Similar Messages

  • How to update duplicate row from table

    Hi,
    how to update duplicate row from table?
    First to find duplicate row then update duplicate row with no to that duplicate row in oracle.
    can you give me suggestion on it?
    Thanks in advance.
    your early response is appreciated...

    In order to find a duplicate row, see:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224636375004
    (or search this forum, your question has been asked before)
    In order to update it, just create and use an Oracle sequence, have it start and increment at a value that doesn't exist in your table.
    If that doesn't get you going, post some CREATE TABLE + INSERT INTO statements, and the results you want from them, in other words: a complete testcase.

  • Procedure to update duplicate rows

    In a table i have some duplicate rows
    I can get it through this query : select PARTY_ID from XXWFS_CUSTOMER_EXT group by PARTY_ID having count (PARTY_ID) > 1;
    Now for the records which i got for each duplicate row i want to update the second row with a specific value.. so that duplicate rows does not exist anymore
    Ex: I got party id's 12, 14, 16, 18 two times each
    Now as 12 is two times.. i want to update the second row of 12 with some x value same is the case for other values like 14,16, etc
    how can i write a procedure for this
    Thanks,

    Hi,
    I think using single UPDATE statement we can do this.
    Please see below example. Please use this according to your requirement.
    SQL> create table test_emp (empno number,ename varchar2(40));
    Table created
    SQL> insert into test_emp values (1,'SURI');
    1 row inserted
    SQL> insert into test_emp values (1,'SURI');
    1 row inserted
    SQL> insert into test_emp values (2,'SRINU');
    1 row inserted
    SQL> insert into test_emp values (2,'SRINU');
    1 row inserted
    SQL> SELECT *
      2  FROM test_emp;
         EMPNO ENAME
             1 SURI
             1 SURI
             2 SRINU
             2 SRINU
    SQL> UPDATE test_emp t2
      2  SET t2.ename = 'X'
      3  WHERE t2.rowid > (SELECT min(t1.rowid)
      4                  FROM test_emp t1
      5                  WHERE t1.ename=t2.ename);
    2 rows updated
    SQL> SELECT *
      2  FROM test_emp;
         EMPNO ENAME
             1 SURI
             1 X
             2 SRINU
             2 X
    SQL> According to your table structure
    UPDATE XXWFS_CUSTOMER_EXT x1
    SET x1.party_id = <SOME X VALUE>
    WHERE x1.part_id = 12
    AND x1.rowid > (SELECT min(rowid)
                    FROM XXWFS_CUSTOMER_EXT x2
                    WHERE x2.party_id = x1.party_id);Cheers,
    Suri
    Edited by: Suri on Mar 14, 2013 7:32 PM

  • Duplicate rows in AdvancedDataGrid when pushing updates via custom Assembler?

    We are trying to use LCDS transactions to dynamically push updates from a server side application via custom Assembler to AdvancedDataGrid.  Latter is using fill result ArrayList as its data source.
    Unfortunately we haven't been fully successful thus far. Grid shows fine initial snapsot delivered by fill but subsequent record updates result in a duplicate rows shown in a grid. 
    We are using Flex 3, SDK 3.5 and LCDS ES 2.6.1.
    Here is the relevant code in our custom assembler to do the update push:
    _results.add(dataUpdate); // _results is the ArrayList object returned with data on the original fill
    DataServiceTransaction dtx = DataServiceTransaction.begin("FOO", false);
    dtx.addItemToFill(_assemblerId, _currentParams, _results.size()-1,dataUpdate);
    dtx.commit();
    // we see this method gets called as result of the code above
    public Object getItem(Map identity) {
          Object item = null;
          String id = identity.get("ID").toString();
          for (LinkedHashMap<String,Object> itemMap : _results) {
          if (itemMap.get("ID").equals(id)) {
                item = itemMap;
           break;
          return item;
    And finally here is the destination configuration for the assembler in the data-management-config.xml file:
    <destination id="updates">
      <properties>    
             <source>UpdatesAssembler</source>
            <scope>session</scope>
      <auto-sync-enabled>false</auto-sync-enabled>
      <metadata>
                     <identity property="ID"/>
      </metadata>
      <network>
                     <paging enabled="false"/>
      </network>
    </properties>
    </destination>
    And naturally, we bind the datagrid dataProvider to the array collection returned by the original fill call.
    As stated above, this solution results in two rows of the same data appearing in datagrid for every updated pushed by the assembler.
    Can you please advise what are we doing wrong.
    Thanks!

    What events are coming back to the client?
    If you add an event listener to the dataService object in ActionScript, you can see what events are coming in.
        dataService.addEventListener(MessageEvent.RESULT, resultHandler);
    This might help diagnose it.

  • Update/Insert Duplicate Rows

    Hi I am loading a target table [empty] for the first time. I am using update/insert strategy. however, it's only inserting. not updating inserted rows.

    In a single mapping and on an empty table you can only insert rows. The Insert/Update strategy will update rows if the matching criteria you have used satisfies on an existing set of rows prior to your running the mapping. In other words you cannot expect OWB to update rows which it has inserted in the same statement !...
    You can try Row Based mode and put an order by clause before inserting into the target table and check to see if the update happens.
    Regards
    -AP

  • Deleting BOTH duplicate rows in Excel

    Hi everyone,
    I have just been introduced to Applescript and I was hoping to automate some things at my workplace. One of the first activities that I have been trying to figure out involves Excel 2008, which is running on a G5 (Latest version of Mac OS X updated just today). It involves deleting both duplicates of records--file numbers--in a long one column list (there may soon be thousands of these records piling up, with many duplicates.)
    Someone over at MacScripter ("mikerickson" @ http://macscripter.net/viewtopic.php?id=32340) posted the following code for using Excel autofilter to delete only one instance of each duplicate row:
    *tell application "Microsoft Excel"*
    *set myMessySheet to get worksheet "Sheet1" of workbook "Workbook2.xls"*
    *set myMessyRange to get current region of range "A1" of myMessySheet*
    *set myCleanRange to get resize (get offset (myMessyRange) column offset ((count of columns of myMessyRange) + 1)) row size 1*
    *advanced filter myMessyRange action filter copy copy to range myCleanRange with unique*
    *-- optional deletes dirty range*
    *delete range (entire column of (get resize myMessyRange column size ((count of columns of myMessyRange) + 1))) shift shift to left*
    *end tell*
    This code works great when I copy and paste in Applescript Editor. Now, I need to find all duplicates in my data and delete both of the numbers, leaving only the single instance records/numbers. There are even instances where a number shows up three or more times; it would be great to get rid of those as well.
    Thank you in advance to anyone who can help me with this.

    I think you're going to have a hard time doing this because the original script used Excel to do the heavy lifting (i.e. filter the duplicates). The keyword with unique in the advanced filter is what's doing that.
    Off hand, I don't see an equivalent option for the filter that finds singletons in the list. Without that you'll need to iterate through the list manually, excluding the duplicate entries.

  • Need to Remove Duplicate Rows

    I have two tables MEMBER_ADRESS and MEMBER_ORDER. The MEMBER_ADRESS has duplicate rows in it based on MEMBER_ID and MATCH_VALUE. These duplicate ADDRESS_IDs were used in MEMBER_ORDER. I need to remove the duplicates from MEMBER_ADRESS making sure I keep the one with PRIMARY_FLAG = ‘Y’ and update MEMBER_ORDER.ADDRESS_ID to the MEMBER_ADRESS.ADDRESS_ID that I kept.
    I am on 11gR1
    Thanks for the help.
    CREATE TABLE MEMBER_ADRESS
      ADDRESS_ID               NUMBER,
      MEMBER_ID                NUMBER,
      ADDRESS_1                VARCHAR2(30 BYTE),
      ADDRESS_2                VARCHAR2(30 BYTE),
      CITY                     VARCHAR2(25 BYTE),
      STATE                    VARCHAR2(2 BYTE),
      ZIPCODE                  VARCHAR2(10 BYTE),
      CREATION_DATE            DATE,
      LAST_UPDATE_DATE         DATE,
      PRIMARY_FLAG             CHAR(1 BYTE),
      ADDITIONAL_COMPANY_INFO  VARCHAR2(40 BYTE),
      MATCH_VALUE              NUMBER(38) GENERATED ALWAYS AS (TO_NUMBER( REGEXP_REPLACE ("ADDITIONAL_COMPANY_INFO"||"ADDRESS_1"||"ADDRESS_2"||"CITY"||"STATE"||"ZIPCODE",'[^[:digit:]]')))
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (200, 30, '11 Hourse Rd.',
        '58754', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:34:10', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 1158754);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (230, 12, '101 Banks St',
        '58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:35:42', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (232, 12, '101 Banks Street',
        '58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:41:15', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (228, 12, '101 Banks St.',
        '58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:38:19', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (221, 25, '881 Green Road',
        '58887', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:34:18', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 88158887);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (278, 28, '2811 Brown St.',
        '58224', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:36:11', 'MM/DD/YYYY HH24:MI:SS'), 'N', 281158224);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (280, 28, '2811 Brown Street',
        '58224', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:45:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 281158224);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ADDRESS_2, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (300, 12, '3421 West North Street', 'x',
        '58488', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:42:04', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 342158488);
    COMMIT;
    CREATE TABLE MEMBER_ORDER
      ORDER_ID    NUMBER,
      ADDRESS_ID  NUMBER,
      MEMBER_ID   NUMBER
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (3, 200, 30);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (4, 230, 12);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (5, 228, 12);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (6, 278, 28);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (8, 278, 28);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (10, 230, 12);
    COMMIT;

    Hi John;
    Sorry I missed your post. Yes sorry about the flag. Please take a look as these before and after sets. I hope this helps. I should have posted this in the begining.
    MEMBER_ORDER (BEFORE)
    ORDER_ID  ADDRESS_ID  MEMEBER_ID
    4       228           12
    10       230           12
    5       230           12
    11       232           12
    12       300           12
    8       278           28
    6       278           28
    3       200           30
    MEMBER_ORDER (AFTER)
    ORDER_ID  ADDRESS_ID  MEMEBER_ID
    4       232           12
    10       232           12
    5       232           12
    11       232           12
    12       300           12
    8       280           28
    6       280           28
    3       200           30
    MEMBER_ADDRESS (BEFORE)
    ADDRESS_ID  MEMBER_ID  ADDRESS_1                    CREATION_DATE             LAST_UPDATE_DATE   PRIMARY_FLAG  MATCH_VALUE
    228         12           101 Banks St.                  8/11/2000 10:56:25 AM     8/12/2005 10:38:19 AM     N     10158487
    230         12           101 Banks St                   8/11/2000 10:56:25 AM     8/12/2006 10:35:42 AM     N     10158487
    232         12           101 Banks Street             8/11/2000 10:56:25 AM     8/12/2007 10:41:15 AM     N     10158487
    300         12           3421 West North Street       8/11/2000 10:56:25 AM     8/12/2011 10:42:04 AM     Y     342158488
    221         25           881 Green Road               8/11/2000 10:56:25 AM     8/12/2011 10:34:18 AM     Y     88158887
    278         28           2811 Brown St.               8/11/2000 10:56:25 AM     8/12/2006 10:36:11 AM     N     281158224
    280         28           2811 Brown Street               8/11/2000 10:56:25 AM     8/12/2011 10:45:00 AM     Y     281158224
    200         30           11 Hourse Rd.                  8/11/2000 10:56:25 AM     8/12/2005 10:34:10 AM     Y     1158754
    MEMBER_ADDRESS (AFTER)
    ADDRESS_ID  MEMBER_ID  ADDRESS_1                    CREATION_DATE             LAST_UPDATE_DATE    PRIMARY_FLAG  MATCH_VALUE
    232         12           101 Banks Street                8/11/2000 10:56:25 AM     8/12/2007 10:41:15 AM     N     10158487
    300         12           3421 West North Street       8/11/2000 10:56:25 AM     8/12/2011 10:42:04 AM     Y     342158488
    221         25           881 Green Road                8/11/2000 10:56:25 AM     8/12/2011 10:34:18 AM     Y     88158887
    280         28           2811 Brown Street              8/11/2000 10:56:25 AM     8/12/2011 10:45:00 AM     Y     281158224
    200         30           11 Hourse Rd.                8/11/2000 10:56:25 AM     8/12/2005 10:34:10 AM     Y     1158754

  • Duplicate rows in Oracle

    What would cause Oracle to insert duplicate rows into a table? Could a join of two tables in the initial query assigned to an application page cause ORacle to insert an extra row into a table when an update to data value occurs? I have no insert triggers and no foreign keys assigned to the table. I am not sure what would cause Oracle to assume that an insert of a row must occur. I want to prevent that insert.

    V Rickert wrote:
    What would cause Oracle to insert duplicate rows into a table? Could a join of two tables in the initial query assigned to an application page cause ORacle to insert an extra row into a table when an update to data value occurs? I have no insert triggers and no foreign keys assigned to the table. I am not sure what would cause Oracle to assume that an insert of a row must occur. I want to prevent that insert.Is there an APEX dimension to this? If so, tell us the full APEX and DB versions, and provide full details of what the APEX app is doing (a debug trace of page accept processing is the obvious place to start).
    The most likely explanations are:
    1. There is no duplicate in the table but there is a join problem in the query reporting on it, resulting in the appearance of a duplicate in the reults. Have you confirmed that the duplicate is really a physical row in the table?
    2. There is an APEX page/application process containing an insert on the table that is unexpectedly running on page accept due to it having no condition or an incorrect condition. This will be visible in the Debug trace.

  • Delete Duplicate rows in Data Package based on selection

    Hello experts,
    I have the data coming from Oracle using DB_Connect. The data has duplicate order no. I need to delete the duplicate rows in the data package based selection before updating the data target.
    I am thinking of writing this in updaterule start routine. I would greatly appreciate any sample code on selective deletion of data package rows.
    Thanks a lot!
    Sri

    Nagesh,
    Thanks for your reply.
    Do I need write this in Update Start routine?
    Another thing the order number field is coming from source system. Currently we are not mapping/assingning to InfoObject. In other words we are not seding order no to data target.
    In my query can I write something like this...
    DELETE ADJACENT DUPLICATES FROM DATA_PACKAGE COMPARING DATA_Package-OrderNo
    Thanks a lot!
    Sri

  • Loading a flat table with duplicate rows in SQL server

    Hi,
    I'm trying to load a flat table with different levels that has duplicate rows. When I'm loading it from my source SQL server enviornment to target SQL server environment.. I can only load 63 rows out of the 1225 rows.. This is happenning because i had to define a primary key on the couple of columns..
    When I just try to load it without a primary key, I get an error that PK needs to be defined for load to happen..
    My table structure looks as follows -
    Lvl1 Lvl2 Lvl3 Lvl4 AccountID AccountDesc
    How do i load all rows of data in my target table using ODI?\
    Please help

    whirlpool wrote:
    Hi,
    I'm trying to load a flat table What is a flat table ? Are you talking about FACT table ?
    When I'm loading it from my source SQL server enviornment to target SQL server environment.. I can only load 63 rows out of the 1225 rows.. This is happenning because i had to define a primary key on the couple of columns..
    When I just try to load it without a primary key, I get an error that PK needs to be defined for load to happen..
    Which IKM is in use ? I can not remember an IKM which needs a PK . Incremental Update IKM needs a Update key which can be a PK or UK at database level or ODI level.
    My table structure looks as follows -
    Lvl1 Lvl2 Lvl3 Lvl4 AccountID AccountDesc
    How do i load all rows of data in my target table using ODI?\
    If you not bother about PK at target then you can go for SQL Control Append to load your target table.
    Thanks,
    Sutirtha

  • FORCE TO "Update document rows to new BP's data"

    How do I force to respond YES in the dialog box "Update document rows to new BP's data?" shows, when I DUPLICATE a marketing document?
    Edited by: Gabriel Marroquin on Sep 25, 2008 6:46 PM

    I want that the user dosen´t have the option to answer NO, that´s I need that the answer always be YES. (If a sales user DUPLICATE an old quotation, wich has a lower price than the actual price of an article, and he answer NO, the actual price of the article doesn´t refresh and the company loose money.)

  • Merge inserting duplicate rows

    Hi,
    I first check if a particular dept_no exists in the table, if not insert into the table. I am getting duplicate rows inserted.
    This is the table data before Merge.
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000This is the table data after Merge.
    3 rows merged.
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000
             4 Ram                  Bharad                       30       2000
             4 Ram                  Bharad                       30       2000
             4 Ram                  Bharad                       30       2000
    6 rows selected.This is the code to merge
    MERGE INTO customer c
    USING ( SELECT cust_id,
                   first_name,
                   last_name,
                   dept_no,
                   salary
            FROM customer ) e
    ON ( c.dept_no = 30 )
    WHEN MATCHED THEN
        UPDATE SET
               c.cust_id    = 4,
               c.first_name = 'Ram',
               c.last_name  = 'Bharad',
               c.salary     = 2000
    WHEN NOT MATCHED THEN
        INSERT
        (c.cust_id,c.first_name, c.last_name,c.dept_no,c.salary)
        VALUES
        (4,'Ram','Bharad',30,2000);Shouldn't the above code insert once, and update twice?
    Thanks

    You have done it wrong...
    Try like this
    SQL> create table customer(cust_id number,first_name varchar2(20), last_name varchar2(20), dept_no number, salary number)
      2  /
    Table created.
    SQL> insert into customer
      2  select 1, 'Dan','Morgan',10,100000 from dual
      3  union all
      4  select 2, 'Jack','Cline',20,100000 from dual
      5  union all
      6  select 3, 'Helen','Lofstrom',20,50000 from dual
      7  /
    3 rows created.
    SQL> commit
      2  /
    Commit complete.
    SQL> select * from customer
      2  /
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000
    SQL> MERGE INTO customer c
      2  USING ( SELECT 4 cust_id,
      3                 'Ram' first_name,
      4                 'Bharad' last_name,
      5                 30 dept_no,
      6                 2000 salary
      7          FROM dual ) e
      8  ON ( c.dept_no = e.dept_no )
      9  WHEN MATCHED THEN
    10      UPDATE SET
    11             c.cust_id    = e.cust_id,
    12             c.first_name = e.first_name,
    13             c.last_name  = e.last_name,
    14             c.salary     = e.salary
    15  WHEN NOT MATCHED THEN
    16      INSERT
    17      (c.cust_id,c.first_name, c.last_name,c.dept_no,c.salary)
    18      VALUES
    19      (e.cust_id,e.first_name, e.last_name,e.dept_no,e.salary);
    1 row merged.
    SQL> select * from customer
      2  /
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000
             4 Ram                  Bharad                       30       2000but beware of the fact that you are joining based on dept_no so multiple rows can get updated with same cust_id. see below.
    SQL> rollback
      2  /
    Rollback complete.
    SQL>  MERGE INTO customer c
      2   USING ( SELECT 4 cust_id,
      3             'Ram' first_name,
      4             'Bharad' last_name,
      5             20 dept_no,
      6             2000 salary
      7      FROM dual ) e
      8   ON ( c.dept_no = e.dept_no )
      9   WHEN MATCHED THEN
    10       UPDATE SET
    11         c.cust_id    = e.cust_id,
    12         c.first_name = e.first_name,
    13         c.last_name  = e.last_name,
    14         c.salary     = e.salary
    15   WHEN NOT MATCHED THEN
    16       INSERT
    17       (c.cust_id,c.first_name, c.last_name,c.dept_no,c.salary)
    18       VALUES
    19       (e.cust_id,e.first_name, e.last_name,e.dept_no,e.salary);
    2 rows merged.
    SQL> select * from customer
      2  /
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             4 Ram                  Bharad                       20       2000
             4 Ram                  Bharad                       20       2000Thanks,
    Karthick.

  • Macro to remove duplicate rows between two worksheets

    Hi
    We have a master file which multiple users access through 'sharepoint'.
    The 'sharepoint' service had an issue, and this master file (which two users spend a day each working on) has not updated.
    We are left with two variations of the same master file, and need to merge them together - allowing adjustments made by both users to stand. The master has 45 columns, and the copies have between 20916 and 21034 rows inc header.
    As I have basic capabilities with Macro's, would someone be able to advise?
    Kind regards
    Metakio

    Re:  Merging two files
    One way...
    In a new workbook, paste copies of the two sets of data onto a single sheet with one set of data directly below the other.
    Use Excel's Remove Duplicates feature to remove the duplicate rows.
    Jim Cone
    Portland, Oregon USA
    free & commercial excel programs
    https://jumpshare.com/b/O5FC6LaBQ6U3UPXjOmX2

  • Using JHS 'Duplicate Row' Feature In Form

    I am having a minor set back in implementing the JHeadstart duplicateRow() method in a Form (opposed to the default Table-view).
    In table-view the duplicateRow() method of the JhsCollectionModel works flawlessly with items that are set to Update Allowed?: while_new. When we use the method in a Form view however, items remain non-updateable after the Duplicate Row button has be pressed. This prevent rows from being copied within the given Form view page.
    I do not understand how this is occuring since row.setNewRowState(Row.STATUS_NEW) is being called within the duplicateRow() method. Is another object (other than oracle.jbo.Row) that needs to be used in Form view instead of Table view in order to perform this functionality?
    Thanks

    Well, after an entire day of playing around, I was finally able to get a proper call to the onCreate() method. I figure out that I could make a hard-coded call to:
    oracle.binding.OperationBinding opBinding = getBindings().getOperationBinding("CreateCampus"); ...to get a OperationBinding interface to a FacesCtrlActionBinding (which extends JUCtrlActionBinding). With a simple cast, this allowed me to make a call to JhsPageLifecycle.onCreate().
    Unfortunately, when the rest of my algorithm runs, it's not "copying" over any of the non-PK row values (as it normally does before I implemented this logic).
    So to simplify things: Has anyone ever coded a simple single-row copying ADF Faces/ADF BC feature before that would work in both Table and Form views? Or, how easily could the JHeadstart duplicateRow() feature be extended to work in Form-view?
    If I can see how a simple shallow copy is supposed to operate within the use of JHeadstart, I think I can extend it for our "deep copying' requirement.
    Thanks.

  • Duplicate rows in apex

    HI
    can you kindly help me. I have issue with duplicate rows with multi row update. I have added to apex.oracle.com can you look into it and tell me where the problem is.
    workspace:- TRY1_APEX
    Username: [email protected]
    password:- 12345678
    Thanks
    Edited by: 970549 on Dec 13, 2012 6:48 PM

    Hi 970549,
    It's good that you provided the workspace details, but you still need to provide much more information.
    Firstly with the workspace - you havent given any indication of what application or page the error is.
    What is the actual problem? What are you trying to do? What have you done?. "Duplicate rows" just doesn't make anything clear of what your requirement is.
    From your current posts, you mentioned multi row update, so i can deduce that you are using a tabular form - is that correct? If so, say that in your initial post.
    What exactly are you trying to do? When the user submits the form, copy all existing rows?

Maybe you are looking for

  • Error while loding the maseter data

    Hi Experts, I am working on BI, I am trying to extract the data from 0PM_MEASDOC_ATTR to PSA, while I am loading the dat I got bellow error. ERROR OCCURED WHILE DECIDING PARTITION NUMBER What could be the problem, How can solve it, please help me to

  • Dvi to Tv extender wire?

    i just got a new flat screen tv and remembered my macbook pro came with the dvi to vga adapter. but the thing is way to short, is there a dvi cable extender so that i can actually use the dvi to vga adapter?

  • I keep getting an error message to reinstall in applications

    I just downloaded the PS,AI suite. I was able to open it the first time I went into applications and set to my tool bar menu. But I think I moved it and now Im getting an errr that asked me to reinstall. I don't see a reinstall?? So, I uninstailled P

  • ESA - External Auth - Spam Quarantine

    I'm looking to see if anyone has a workaround for admins logging into Spam Quarantine and not being able to set their safelist / block list.  I'm using AD accounts for TACACS+ / Radius on my ACS 5.4 appliance and I found an issue when using Radius fo

  • Listen to "ALL" HTTP Requests

    Hello, I have an application with many 3rd party components on it. These components pull in a lot of external media (i.e images, data) but do not have a public Loader i can listen too. Is there any way Flex can give me access to all HTTP request comi