Procedure to update duplicate rows

In a table, I have a few duplicate lines

I can get it through this query: select PARTY_ID from the XXWFS_CUSTOMER_EXT by PARTY_ID group saw County (PARTY_ID) > 1;

Now for the record I got for each duplicate row, I want to update the second row with a specific value... so the duplicate rows that no longer exist

Ex: I went 12 ID, 14, 16, 18 twice each

Now that 12 is twice... I want to update in the second row of 12 with a value of x is the same for other values like 14.16, etc.

How can I write a procedure for this

Thank you

Hello

In my view, using the single UPDATE statement, we can do.

Please see the example below. Please use it 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 the structure of your table

UPDATE XXWFS_CUSTOMER_EXT x1
SET x1.party_id = 
WHERE x1.part_id = 12
AND x1.rowid > (SELECT min(rowid)
                FROM XXWFS_CUSTOMER_EXT x2
                WHERE x2.party_id = x1.party_id);

See you soon,.
Suri

Published by: Suri on 14 March 2013 19:32

Tags: Database

Similar Questions

  • separate notice of motion returns duplicate rows; Why and how to prevent?

    I have 2 tables with b.SID a.firstname b.blob and b.id a.id.

    one can have duplicate rows; b not.

    When I do a

    Select a2.name, a2.firstname, b.blob from (select distinct a.id, b.SID, a.firstname a) a2, b where a2.id = b.id (+)

    I get only unique records.

    When I create a view that selects

    create view c as select a2.name, a2.firstname, b.blob from (select distinct a.id, b.SID, a.firstname a) a2, b where a2.id = b.id (+)

    and I select * c I get duplicate lines.

    I don't know what I'm doing wrong here.

    Any help?

    Hello

    Display online ensures that only unique combinations (id, name, first name) table will be used, but the main result set does not include id, so there is no guarantee that the production lines of the main request will be unique.

    Some results you get, you should get the same results if you create a view or not.  As Paul says, post a test script complete that people who want to help you can to recreate the problem and test their ideas.

  • Help to update all rows in the Table with a sequence

    Hi all

    I have a table with the name Report_Status, now we have added a new [Batch_ID] column in the table. The new column takes a value in a sequence. Can someone tell me a normal SQL queries or the procedure for updating each line in turn to an existing table in the value of the sequence? We cannot delete the existing data, must be added for each record batch code.

    example of name of sequence: Report_Status_Batch_ID_SEQ

    Report_Status name and the column name of the table Batch_ID

    Thanks for your time to help out me.

    Kind regards

    Ashish

    Thanks John,

    or I could write as update dept set id = ID_SEQ. NEXTVAL;

    This also works. Thanks for the idea.

  • Update my application. What is the proper procedure for updating an app/folio?

    I designed a folio in Indesign CS6 and created a folio application in adobe dps and downloaded successfully on the app store. Now, I want to update my application. What is the proper procedure for updating an app/folio?

    If it's a simple editing application, you will have to recreate the whole thing and

    submit an Apple update for approval.

  • In the form of table-update of rows based on the selection of the checkbox

    Hi all

    I have a tabular layout with line selector. I need to update manually checked columns, how would write a process audited records updated?

    Something like this:
    BEGIN     
         FOR i in 1..apex_application.g_f01.count LOOP
    
              IF apex_application.g_f01(i) is not null THEN
                   UPDATE TEST_USERS
                        set USER_ID = :P14_TO
                   WHERE rowid = :APEX$ROW_ID;
                   COMMIT;
              END IF;
         END LOOP;
    END;
    Thank you very much.

    You can refer to the line that you want to process through the value stored in the box.

    If you use apex_application.g_f01 (i) to make reference to the line and you want to update the row based on the ROWID in your request, your SQL query should have the box as follows:

    apex_item. CheckBox2 (1, rowid)

    Then your PLSQL process would be like this:

    BEGIN
         FOR i in 1..apex_application.g_f01.count LOOP
    
              IF apex_application.g_f01(i) is not null THEN
                   UPDATE TEST_USERS
                        set USER_ID = :P14_TO
                   WHERE rowid = APEX_APPLICATION.G_F01(i);
                   COMMIT;
              END IF;
         END LOOP;
    END;
    

    I hope this helps.

    Cheers, Pete

  • Problem updated 16 rows, it updates all rows in the table

    I tried to update of 16 ranks with AL as the name of divion with the script as below:

    Update wire_center set a.wg_id = '63'
    where EXISTS (select b.div_name from wire_center, title b, area c, ns_workgroups d).
    where B.DIV_NAME =' al ' AND a.dis_id = c.dis_id and b.div_id = c.div_id and d.wg_id = a.wg_id);

    When I run it, it updates all rows in the table.

    However when I run the select subquery, it returns 16 ranks.

    It seems where EXISTS is the problem. If I exist, it gave me error ora-00936.

    How to fix? Need urgent help please. DB is 10g.

    Thanks in advance.

    If I understand correctly what you want, you must not include wire_center once again in the second select (in your clause).
    The second selection has no relationship to the table you're updating, so because select the second returns 16 rows, it is always set to true will. For each line. If all the rows will be updated.

    Instead of

    Update wire_center a set a.wg_id='63'
    where EXISTS (select b.div_name from wire_center a, division b, district c, ns_workgroups d
    where B.DIV_NAME='AL' AND a.dis_id=c.dis_id and b.div_id=c.div_id and d.wg_id=a.wg_id );
    

    Try this:

    Update wire_center a set a.wg_id='63'
    where EXISTS (select b.div_name from division b, district c, ns_workgroups d
    where B.DIV_NAME='AL' AND a.dis_id=c.dis_id and b.div_id=c.div_id and d.wg_id=a.wg_id );
    

    Published by: big on 29-dec-2010 14:27

  • How to remove duplicate rows (not exactly duplicate)

    Hi I have lines like this in a table emp

    ENO ename age
    1 25
    26 2
    3 25
    4 26

    I don't have repititve enames... (here in this example: A).

    If I find something like that I should keep the first line and delete all other lines.

    How can I do this?

    as unique empowerment of ename... (except for this)

    Hi Renon,
    There are different ways could remove duplicate rows, but Franks solution seems good.
    With the help of ID you can get good results in the largest data sets. If you want Nwe minutes remain in the database and all others to delete then make use of eno and not rowid.

    DELETE FROM emp y
    WHERE       eno != (SELECT   Min(eno)
                        FROM     emp x
                        WHERE    x.NAME = y.NAME
                        GROUP BY NAME)
    

    HTH
    SS

  • call sub procedure for updating the table - need help

    Hi all

    I have a scneario wherein I get three values 0,2.5 and 57.
    For each value, I'll call another procedure that updates a table "sample_dest".
    The "sample_dest" table has a column "dest_nbr."

    Now, for each three values I get,
    I want to update only one record in the table 'sample_dest '.

    for example, I want to update the column "dest_nbr" with a value of 59.5 (0 + 2.5 + 57).

    I am unable to do this, because every time the procedure is called,
    the previous values are not stored. 57 is the last value I get,
    I am able to store only 57. But I want 59.5 to be updated in the table.

    How can I achieve this.
    Help, please.

    Concerning
    Rambeau.

    This should be done in a single sql statement, not in a loop of cursor (which is what it looks like you're doing). If sample_desc already contains records for samples, so it should look like:

    UPDATE sample_desc sdesc
    SET desc = (SELECT AVG(code) FROM sample_dest sdest
                WHERE sdesc.sample = sdest.sample)
    WHERE EXISTS (SELECT 1 FROM sample_dest sdest
                  WHERE sdesc.sample = sdest.sample)
    

    If sample_desc does not already contain records (unknown from your description), then it would be an insert as:

    INSERT INTO sample_desc
    SELECT sample, AVG(code)
    FROM sample_dest sdest
    GROUP BY sample
    

    John

  • Update for duplicate rows

    Hi,
    
    Can someone plesae help me to write a update statement.
    
    this is my original outpit. I need a update statement.
    
    Vechical Id     City
    1          BOS
    1          BOS
    1          BOS
    2          TEX
    2          TEX
    3          LOS
    3          LOS
    3          LOS
    3          LOS
    4          MEX
    
    Can I have a update statement that will do as follows.
    If Duplicate City for duplicate Vechical no then set city as null
    
    Vechical Id     City
    1          BOS
    1          
    1          
    2          TEX
    2          
    3          LOS
    3          
    3          
    3          
    4          MEX
    
    thanks
    Saaz
    update table_name
    set city=''
    where rowid not in(select max(rowid) from table_name group by Vechical_Id, City);
    
  • Release of stored procedure after UPDATE

    Hello
    I've written a LOOP that calls a second stored procedure.
    In the second stored procedure, I have 3 INSERTS the values of each SELECT limited with a WHERE clause.

    Example:
    begin
    
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012' --if not condition not met, no insert
    execute immediate dynsql;
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012'
    execute immediate dynsql;
    
    
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'  --if not condition not met, no insert
    execute immediate dynsql
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'
    execute immediate dynsql;
    
    
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012'  --if not condition not met, no insert
    execute immediate dynsql;
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between  '01.JUN.2012 and '01.JUL.2012'
    execute immediate dynsql;
    
    end;
    
    
    
    commit;
    What should I do?
    I update the existing line of 'old' with a new date, and then I'm basically duplicate this line but add a new DATE, the NAME and the ID is 'copied' as it is.
    The big problem is that the lines of recursive updates. If the first statement updates a date, it could become a 'true' conditions for the second and the first update
    That is not what I want. Initially, only one of the instructions is true, never. The problem with my code, is that after the first update and the setting of the date, the other "could" become reality.
    This should stop. After the update has occurred, I need to stop the stored procedure.

    How can I stop put an after?

    Use sql % rowcount after an immediate execution.

    If sql % rowcount = 0, no line have been set to day/insert/selected.
    If sql % rowcount > 0 then lines have been updated/inserted/selected day.

  • Change in the merger of insert and create a procedure for updating the records after

    Hello

    I have a table that contains about 50 M lines of partition, and every day I have an application that performs a merge to insert records statement about 100 k per day and it's 300 M updates a day.

    Because I both update and insert the application performs a merge.
    I need to make at least 500 M, updated day by day, and for this reason this solution doesn't have enough performance for what I'm asking.

    I think another solution that I will try to implement now, and I just posted this in an attempt to get help on the option that I may have to do.

    I want to start putting in place:
    -Locations is updated 'last_record_date' using 'KEY1' and 'Key2' "KEY3";
    -Change the application to only inserts into a temporary table.
    -Have two procedures, one that takes the new records from the temporary table and inserts it into the final table, and another that selects records which is updated and perform an update.
    -This two procedures will choose the records and delete them from the temporary table (or mark them as updated\inserted).

    The volume is very large, so performance is a challenge! That's why I'm writing this, because a solution with enough performance for the intermediate stage will be difficult.
    My final table is partitioned by date and the date is the area that I need to update (instead of create daily partitions in order to reduce the frequency of the movement of the line, I create monthly partitions)!
    It is currently my table definition:
    CREATE TABLE MY_TEST_TABLE
        (KEY1                           VARCHAR2(50 BYTE) ,
        KEY2                         VARCHAR2(50 BYTE) NOT NULL,
        KEY3                           VARCHAR2(50 BYTE) ,
        last_record_date                    VARCHAR2(50 BYTE) NOT NULL)
      PCTFREE     10
      INITRANS    1
      MAXTRANS    255
       STORAGE   (
        BUFFER_POOL DEFAULT
      )
      NOCACHE
      MONITORING
      ENABLE ROW MOVEMENT
      PARTITION BY RANGE (last_record_date)
      (
      PARTITION MY_TEST_TABLE_201112 VALUES LESS THAN ('20120101')
      PCTFREE     10
      INITRANS    1
      MAXTRANS    255
      NOLOGGING,
      PARTITION MY_TEST_TABLE_201201 VALUES LESS THAN ('20120201')
      PCTFREE     10
      INITRANS    1
      MAXTRANS    255
      NOLOGGING,
      PARTITION MY_TEST_TABLE_201202 VALUES LESS THAN ('20120301')
      PCTFREE     10
      INITRANS    1
      MAXTRANS    255
      NOLOGGING,
      PARTITION def VALUES LESS THAN (MAXVALUE)
      PCTFREE     10
      INITRANS    1
      MAXTRANS    255
      NOLOGGING
      )
      NOPARALLEL
    /
    
    
    
    -- Constraints for MY_TEST_TABLE
    
    ALTER TABLE MY_TEST_TABLE
    ADD CHECK ("KEY1" IS NOT NULL)
    /
    
    ALTER TABLE MY_TEST_TABLE
    ADD CHECK ("KEY2" IS NOT NULL)
    /
    
    ALTER TABLE MY_TEST_TABLE
    ADD CHECK ("KEY3" IS NOT NULL)
    /
    ALTER TABLE MY_TEST_TABLE
    ADD CONSTRAINT pk_MY_TEST_TABLE PRIMARY KEY (KEY1, KEY2, KEY3)
    USING INDEX
      PCTFREE     10
      INITRANS    2
      MAXTRANS    255
    /
    Thank you
    Ricardo Tomas

    naoseionome wrote:
    Hello

    My version is:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    It's the DOF I used to create the database.

    The merger is common during every day for about 10 M records.

    There are several methods to do the update, but they do sequencially to avoid deadlocks (because I can't control the source and each process can update the same keys.

    The update uses "KEY1, KEY2, KEY3" to update the value 'LAST_RECORD_DATE' have impact by being date or varchar2?

    I'm still waiting to receive permissions in order to follow up the matter, but in the meantime, in that I am trying to implement this work around in order to accelerate a development in the case where it would be necessary! Comments only I have at the moment, it is that he is not able to process the total amount of records timely (order book is generated).

    Thank you
    Ricardo

    Well, the first thing we do is to change the type of data type varchar to a date. The main impact is that a date is not a string, it's a date. If you are adding data processes in different date formats (which is possible when you use a character to store information) you're going to be very sad (good luck converting back an effective date).

    An example of how this can happen easily.

    ME_TUBBZ?select to_char(sysdate) from dual;
    
    TO_CHAR(SYSDATE)
    -----------------------------
    12-jan-2012 10 55:33
    
    1 row selected.
    
    Elapsed: 00:00:00.01
    ME_TUBBZ?alter session set nls_date_format = 'yyyy-mon-dd';
    
    Session altered.
    
    Elapsed: 00:00:00.01
    ME_TUBBZ?select to_char(sysdate) from dual;
    
    TO_CHAR(SYSDATE)
    --------------------
    2012-jan-12
    
    1 row selected.
    
    Elapsed: 00:00:00.00
    

    Assuming that the client passes the column as an Oracle DATE will make an (implicit) conversion to store the data as a string, which will be based on the current settings of the NLS for the session. This allows also for someone to completely non-jour the information in the column (super bad). It's just really bad form to use strings to store dates, numbers, anything that is not naturally a string.

    Based on the description of your problem, I can't imagine how your partitioning scheme performs one action in another that require more work in order to process the updates (which are most of your needs). Partitioning does not equate to increase performance. It is a tool that, like every tool has its place, but I do not think that this is justified for what you do (certainly not how you currently use it anyway).

    I say no partitioning can not be useful for you, but I don't think that on the column that you are currently using is 'good '.

    Something I would like to personally study (must be able to compare this approach to your course, if you need parameters for comparison) if I were you would be using a Table Index organized for it. It will take more time to perform the operations insertion, but that is a small part of all the work that you do for this process. For updates, it should eliminate a lot of IO, assuming that you are doing an INDEX seek followed by a table access by ROWID to perform updates. This recommendation assumes that everything you said is true. You have 4 columns in your table, of which 3 are components of the primary key and the 4th is a date (note I did not string :)) and that you refresh mainly, not fit.) Also that you have no 'secondary' on this entity index (and none are needed).

    I would investigate this approach before the solution of temporary table that you are currently studying.

    See you soon,.

  • Update multiple rows in a table at a time

    Hi all

    I write a stored procedure that fills all columns in a table, that table with a query with the exception of a single column, say 'ABC' column in this table. I have to load this left on column using a different query that refers to some other tables. How can I update this column 'ABC' with all its rows of data from a different query?

    Thank you very much!!

    If you post an update with a create table and insert statements, it would be useful... I think that you want to update a table with a select from another table using a join... is that correct?

    c customer update
    Set client_name =)
    Select client_name
    of another_customer_table one
    where a.customer_id = c.customer_id_from_original_customer_table
    )
    where c.customer_id in (select customer_id from another_customer_table)

    Where clause is required only if you don't want to update missing customer_ids to null.

  • I have several updates duplicate in my history of microsoft update. Should I remove them?

    I had problems during the installation of updates after reinstalling windows. I used the update of microsot and restored to the computer when I drop functions

    the facility out of service. I any day now, but I have several duplicates in the history on microsoft update file. Should I remove these

    or just ignore them? I ask because they appear in the story, only one instance is in my control panel. Any thoughts?

    It is not history that is important, but what is installed.

    You can ignore history.

  • BlackBerry Smartphones step by step procedure to update OS

    Guys,

    I think I'm ready to try to update my OS.  Is this useful?  Do I have telecharger.99 now, ane.101 then the next week?  Or should I just wait until March 31, when they officially release a new?

    Could someone provide a procedure step by step to do this and do it right the first time...?  Will be deleted all the software that I downloaded?  Can I backup my stuff? How can I download it all back on my device after the upgrade?

    This is a trick question, but I think it can be one-stop shopping for everyone thinking about upgrading.

    Thank you!

    Hello!

    Try to read this thread:

    http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=9500&message.ID=17462#M17462

    Krypto wrote a nice procedure to make updates.

  • Need a script to select the update the row to another row in the same table

    I have a table with the columns and values
    KeyID       EffectiveDate     InactiveDate
    1              01/01/2013
    1              01/02/2013
    1              01/03/2013
    2              12/31/2012
    2              01/02/2013
    2              01/03/2013
    I need to update the InactiveDate of a line with the EffectiveDate of a line with the EffectiveDate newer than the update line and the even KeyID.
    KeyID       EffectiveDate     InactiveDate
    1              01/01/2013      01/02/2013
    1              01/02/2013      01/03/2013
    1              01/03/2013
    2              12/31/2012      01/02/2013
    2              01/02/2013      01/03/2013
    2              01/03/2013
    I want to have a select script that shows
    KeyID       EffectiveDate        InactiveDate    New_InactiveDate
    1              01/01/2013                              01/02/2013
    1              01/02/2013                              01/03/2013
    1              01/03/2013
    2              12/31/2012                              01/02/2013
    2              01/02/2013                              01/03/2013
    2              01/03/2013
    Thanks for any help.

    Published by: 881656 on January 3, 2013 17:57

    Published by: 881656 on January 3, 2013 18:15

    Published by: 881656 on January 3, 2013 18:20

    Hello

    881656 wrote:
    I have a table with the columns and values

    KeyID       EffectiveDate     InactiveDate
    1              01/01/2013
    1              01/02/2013
    1              01/03/2013
    2              12/31/2012
    2              01/02/2013
    2              01/03/2013
    
    I need to update the InactiveDate of a row with the EffectiveDate of a row with the newer EffectiveDate than the row to be updated and with the same KeyID.
    
    KeyID       EffectiveDate     InactiveDate
    1              01/01/2013      01/02/2013
    1              01/02/2013      01/03/2013
    1              01/03/2013
    2              12/31/2012      01/02/2013
    2              01/02/2013      01/03/2013
    2              01/03/2013
    

    This sounds like a job for the analytical function of LEAD:

    MERGE INTO table_x     dst
    USING (
         SELECT  keyid
         ,     effectivedate
         ,     LEAD (effectivedate) OVER ( PARTITION BY  keyid
                                           ORDER BY         activedate
                                         )            AS inactivedate
          )               src
    WHEN MATCHED THEN UPDATE
    ON    (    src.id          = dst.id
          AND  src.effectivedate     = dst.effectivedate
          )
    SET     dst.inactivedate     = src.inactivedate
    ;
    
    I want to have a select script which shows
    
    KeyID       EffectiveDate        InactiveDate    New_InactiveDate
    1              01/01/2013                              01/02/2013
    1              01/02/2013                              01/03/2013
    1              01/03/2013
    2              12/31/2012                              01/02/2013
    2              01/02/2013                              01/03/2013
    2              01/03/2013
    

    Once that you have done the above MERGER, it is simply:

    SELECT    *
    FROM      table_x
    ORDER BY  keyid
    ,         effectivedate
    ;
    

    If you do not have sthe FUSION, then see the query in the USING clause of the MERGER.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
    In the case of a DML (UPDATE), for example, the sample data should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

Maybe you are looking for