Insert the merge problem

Hello

I am running a merge as a statement.

FUSION
IN dmt_cust C
With the help of uni_cust E

On(c.ID_Number = e.ID_Number)

WHEN MATCHED THEN UPDATE

C.cust_type = c.cust_type SET etc ect

WHEN NOT MATCHED THEN
INSERT statement

dmt_cust table is empty and uni_cust table has a duplicate primary key. I want to insert all records from uni_cust to dmt_cust and so no record of dupicate found I want to update some fields in the record. When I run this query occurs primary key violation exception. Please help me how I can perform this action.

Thank you

Bilal.

Something like

SQL> create table customer(id_number number primary key
                     ,full_name varchar2(20)
                     ,father_name varchar2(20)
                     ,permanent_address1 varchar2(20))
Table created.
SQL> merge into  customer t
using (select id_number
             ,max(full_name) full_name
             ,max(father_name) father_name
             ,max(permanent_address1) permanent_address1
 from (
with t as (select 1001 id_number, 'TAHIR' full_name, 'BILAL' father_name, null permanent_address1 from dual
           union all
           select 1001 id_number, 'TAHIR' full_name, null father_name, '669 UK' permanent_address1 from dual)
select * from t)
group by id_number) s
on (t.id_number = s.id_number)
when matched
  then update set t.full_name = s.full_name
                 ,t.father_name = s.father_name
                 ,t.permanent_address1 = s.permanent_address1
when not matched
  then insert (id_number, full_name, father_name, permanent_address1)
       values (s.id_number, s.full_name, s.father_name, s.permanent_address1)
Merge successfully completed.
SQL> select * from customer

 ID_NUMBER FULL_NAME            FATHER_NAME          PERMANENT_ADDRESS1
---------- -------------------- -------------------- --------------------
      1001 TAHIR                BILAL                669 UK
1 row selected.

Concerning
Peter

Tags: Database

Similar Questions

  • Insert the Ajax problem

    Hello

    I have the following problem:
    I want to create a form to insert something into the database. Everything worked well.
    Then I changed the source of an item of "The database column" in "Query SQL (simple return)" to provide a dynamic value.
    Now when I try to insert data I get always the exception that the value of the changed item is null, but the value is not null.
    Maybe the mapping of the element and the database does not work because the issue is no longer a database column.

    How can I get this to work?
    Thank you for your solutions :)

    Hi 982994,

    If you use a treatment of automatic line (DML), the column must be defined as data base.
    You can create your own hidden procedures DML to manage data or to use dynamic measures for dynamic value (which means in your example) or to create the database item and fill it with your 'point of dynamic value' on submit.

    BTW, where is AJAX here?

    BR,
    Marko Goricki
    ---------------------------
    http://apexbyg.blogspot.com/

    Published by: Marko Goricki on January 21, 2013 09:04

  • 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,.

  • Problem in the merge command

    When I tried to run this identifier not valid to B.DEPTNO

    merge into dept3 b
    using c dept
    on (b.DEPTNO = c.DEPTNO)
    When matched then
    setting a day of set b.DEPTNO = b.DEPTNO,
    b.DNAME = b.dname,
    b.loc = b.loc,
    b.Country_ID = b.Country_ID
    When not matched then
    Insert the values(c.DEPTNO,c.DNAME,c.LOC,c.COUNTRY_ID);

    Shiv kumar says:
    In fact it has been in front of mistakely, same problem
    merge into dept3 b
    using c dept
    on (b.DEPTNO = c.DEPTNO)
    When matched then
    setting a day of set b.DEPTNO = c.DEPTNO,
    b.DNAME = c.dname,
    b.loc = c.loc,
    b.Country_ID = c.Country_ID
    When not matched then
    Insert the values(c.DEPTNO,c.DNAME,c.LOC,c.COUNTRY_ID);

    The closer you get on (b.DEPTNO = c.DEPTNO) and updates the same as b.DEPTNO = c.DEPTNO set

    Why?

  • Why do I receive flag showing that I have a problem and insert the disc. but nothing shows

    Why do I get a red flaag showing I have a problem and to insert the blank disc aa, what I do, but the flag persists?

    Hello

    • What disk you insert?
    • What are the instructions?
    • How long have you been faced with the question?
    • Are there changes to the computer?
    • The problem is present in Safe Mode and clean the boot?
     
    I suggest you run the Analysis System File Checker and see if TI the problem still occurs. To do this, please see the following article.
  • Problems become more problems... DISK BOOT FAILURE, INSERT THE FLOPPY DISK AND PRESS ENTER

    I recently had a question on my toolbar menu and begin to disappear.  While I was trying a number of different ideas through forums, I myself in another problem.  Now my computer boots but windows never start I just get a screen saying: "FAILURE of STARTUP DISK, INSERT the DISK AND press ENTER.  It worries me because my computer never came with a CD-ROM it was all preloaded when I bought.  Can anyone help, thanks

    Home premium Windows Vista, 64-bit operating system

    Hello

    Here are the different ways to reinstall Vista

    Contact the manufacturer of the laptop computer and ask them to send you to vista recovery disks to reinstall the operating system back as it was when you bought it

    they do it for a nominal cost of $

    ____________________________________________________________

    also ask them if you have a recovery partition on your hard drive to get back to the way you bought

    you would normally press F8, F9, F10 or F11 or Alt + F10 or 0 to start to start the recovery process according to the manufacturer

    Ask them of the exact key sequence

    __________________________________________________________

    or borrow a vista microsoft dvd; not a HP, Acer recovery disk etc

    Make sure that you borrow the correct 32-bit or 64-bit microsoft dvd to your computer

    they contain all versions of vista

    This is the product key that determines which version of vista is installed

    http://www.theeldergeek.com/Vista/vista_clean_installation.html

    ____________________________________________________________

    How to replace Microsoft software or hardware, order service packs and replace product manuals

    http://support.Microsoft.com/kb/326246

  • I installed the download tool usb/dvd windows 7, but after you have selected the iso file when I insert the USB stick and refrecing, it does show that "no usb drive compatible' what is the problem with my USB

    I installed the download tool usb/dvd windows 7, but after you have selected the iso file when I insert the USB stick and refrecing, it does show that "no usb drive compatible' what is the problem with my USB

    I have sandisk cruzer blade USB key

    Hi Rohit,

    Thanks for posting your query in Microsoft Community Forum. I understand that your USB drive is having problems of compatibility with your computer, but I would like to learn more about the issue in order to provide you with better assistance.

    1. You did it any significant hardware or change software on the computer before this problem?
    2. When do you get exactly the error message?
    3. Have you tried to connect to any other computer on this flash drives?
    4. Your USB key works on other computers or have you tried to connect to different USB ports on this computer?
    5. Is the pen drive getting detected in the case or you are able to access the drive folder in the window of the computer ?

    The question may arise if the currently loaded USB driver has become unstable or damaged, or if your PC requires an update for problems that could conflict with a device USB and Windows. This can also occur if your USB controllers may have become unstable or corrupt. So, I would suggest trying the following steps and check if the problem persists.

    Method 1:

    Please try the fixit (s) provided below which will help you solve common problems associated with devices and USB ports.

    If method 1 does not work, try Method 2.

    Method 2:

    Remove and reinstall all USB controllers.

    1. Open Manager devices by clicking the Start button, click Control Panel, click system and security, and then, under System, clicking Device Manager. If you are prompted for an administrator password or a confirmation, type the password or provide confirmation.
    2. In the list of the categories of equipment, locate and expand Bus USB controllers.
    3. Right-click every device under the Bus USB controllers node and then click Uninstall to remove them one at a time.
    4. Restart the computer and let the USB controllers get reinstalled.

    Plug in the removable USB device and test to make sure that the problem is solved.

    If the problem persists, go to method 3.

    Method 3:

    This method will install the latest drivers from device to your USB device.

    1. Click the Start button, type Windows Update in the search box, and then click Windows Update in the results pane.
    2. Click find updates. When the scan finished, click optional review updates.
    3. Click the check box next to the update, and then click install updates.
    4. If you are prompted, read the license agreement, then click I agree.
    5. Follow the instructions on the screen to download and install updates.
    6. If you are prompted, restart your computer.

    More information: Update a hardware driver that is not working properly

    Hope this information is useful. If the problem still persists, please post back for further assistance, we will be happy to help you.

  • I can't activate Windows 7, when I insert the product note key, which is an error 0xC004F063 problem code. What do I do?

    I can't activate Windows 7, when I insert the product note key, which is an error 0xC004F063 problem code. What do I do?

    Boost telephone:

    Activate Windows 7 manually:

    1. click on start and in the search for box type: slui.exe 4

    2. press enter on your keyboard

    3. Select your country.

    4. Select the telephone activation option and brace yourself for a real person.

    This is the Forum for Windows Update.

    You will get the best help for any problem of activation in Windows 7 install, upgrade and activate Forum. the link below:

    http://social.answers.Microsoft.com/forums/en-us/w7install/threads>

    UTC/GMT is 23:41 Friday, January 20, 2012

  • I can't install my Adobe Acrobat 9 Pro in my new HP Pavilion all-in-one computer desktop drive, because my new HP does not insert the disc in a disc drive.  What can I do to fix this problem?

    I can't install my Adobe Acrobat 9 Pro in my new HP Pavilion all-in-one computer desktop drive, because my new HP does not insert the disc in a disc drive.  What can I do to fix this problem?

    Hi edwards39572619 ,

    Please visit this link to download Acrobat 9 Pro:-download Acrobat 8 and Acrobat 9

    Let me know how it goes.

    Kind regards

    Christian

  • When I select a sequence of five frame to render HDR in Lightroom it merges files in a preview very well. But when I click on the Merge option, the progress bar is obstruction of about 42% complete. I suspect a memory problem, so I spent a few hours Unite

    When I select a sequence of five frame to render HDR in Lightroom it merges files in a preview very well. But when I click on the Merge option, the progress bar is obstruction of about 42% complete. I suspect a memory problem, so I spent a few hours uninstalling a bunch of useless software on my laptop and still photography will not merge the HDR sequence. It worked once before, but now it does not work. Help!

    I just 8 GB of RAM and have been able to put together five separate images HDR images. I compared these files 5-image HDR with files - 2 and 3-image and see improvement very few (if any) using all five. Your results may vary, but you can try to reduce the number of images until you get your new laptop.

  • Insert the problem using a SELECT table with an index by TRUNC function

    I came across this problem when you try to insert a select query, select returns the correct results, but when you try to insert the results into a table, the results are different. I found a work around by forcing a selection order, but surely this is a bug in Oracle as how the value of select statements may differ from the insert?

    Platform: Windows Server 2008 R2
    11.2.3 Oracle Enterprise Edition
    (I've not tried to reproduce this on other versions)

    Here are the scripts to create the two tables and the data source:
    CREATE TABLE source_data
    (
      ID                 NUMBER(2),
      COUNT_DATE       DATE
    );
    
    CREATE INDEX IN_SOURCE_DATA ON SOURCE_DATA (TRUNC(count_date, 'MM'));
    
    INSERT INTO source_data VALUES (1, TO_DATE('20120101', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120102', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120103', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120201', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120202', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120203', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120301', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120302', 'YYYYMMDD'));
    INSERT INTO source_data VALUES (1, TO_DATE('20120303', 'YYYYMMDD'));
    
    CREATE TABLE result_data
    (
      ID                 NUMBER(2),
      COUNT_DATE       DATE
    );
    Now, execute the select statement:
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM')
    You should get the following:
    1     2012/02/01
    1     2012/03/01
    1     2012/01/01
    Now insert in the table of results:
    INSERT INTO result_data
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM');
    Select the table, and you get:
    1     2012/03/01
    1     2012/03/01
    1     2012/03/01
    The most recent month is repeated for each line.

    Truncate your table and insert the following statement and results should now be correct:
    INSERT INTO result_data
    SELECT id, TRUNC(count_date, 'MM')
    FROM source_data
    GROUP BY id, TRUNC(count_date, 'MM')
    ORDER BY 1, 2;
    If someone has encountered this problem before, could you please let me know, I don't see what I make a mistake because the selection results are correct, they should not be different from what is being inserted.

    Published by: user11285442 on May 13, 2013 05:16

    Published by: user11285442 on May 13, 2013 06:15

    Most likely a bug in 11.2.0.3. I can reproduce on Red Hat Linux and AIX.

    You can perform a search on MOS to see if this is a known bug (very likely), if not then you have a pretty simple test box to open a SR with.

    John

  • Problem: Blending options change when the merged layers

    Hello.

    I have a problem with the merge options. When I merge two files that both have effects, I get a layer display does not resemble the front. It looks like some options I applied seems to be 30% of what they were. For example, I got a text in a single layer with bevel and applied stamping and another layer (bottom box) with shadow bevel and inner. Now, when I merge these two, I can see looking bevel effect as the opacity is set to 30% for them, the text and the background remaining intact. Effect similarly degraded and not the shadow that was applied as weel looks like changed, but change the bevel cut.

    I noticed that if I turn this layer with the effect bevel in smart object, same thing happened. But even once, gradient stay unmodified.

    The general mix options are by default, normal mode, opacity 100, complete knockout 100, opacity, none, RGB, mix of Cup and the form of transparency is checked on. I didn't change anything there.

    Bevel options are: Pillow emboss, smooth, 100% depth, direction up, size 4, soften 0, angle 90, altitude 30...

    Any help?

    Thank you

    View 100% of the size when you merge. Do, they are different then?

  • Insert (ignore duplicates) have a better performance than the merger?

    Insert (ignore duplicates) have a better performance than the merger (insert if not duplicated)?

    Well, it isn't that much of a performance issue if you need to insert in respect of business rules (your unique index), is it?
    In any case, the MERGE statement is quite effective. You also have the option to INSERT NOT EXISTS, or as I said above the ERRLOG option...
    But as already said earlier, hard to say which option will be faster without knowing anything of your system (application, OS version,...).

    Nicolas.

  • insert/update County in the merge statement

    In the Merge statement, we can count the number of inserted rows and updated?

    ROWCOUNT SQL % simply returns the number of rows merged.

    It does not tell us the separately the line inserted and updated.

    # To insert the rowcount is the number of inserted rows for update is the number of rows updated, for the merger, that's the number of merged lines.

  • I have some problems with a ONE_TO_MANY relationship, can not insert the record

    I have some problems with a ONE_TO_MANY relationship:

    Imagine the following entities:

    -J' have an operational entity with a relationship to workers one_to_many something like:
    @SecondaryKey(relate = Relationship.ONE_TO_MANY,
        relatedEntity = Worker.class)
        private Set<String> workers;
    -The category of workers is a simple annotated entity.


    Now, I want to do the following and I get the error:

    -Create a bunch of tasks
    -Insert tasks into the entitystore
    -create a set containing all the tasks of primary key
    -involve workers to tasks
    -Insert the task in the database


    The above procedure works fine, but when I try to associate the same set of workers with another task I get an exception like:
    com.sleepycat.je.DatabaseException: (JE 3.3.75) Could not insert secondary key in persist#Sample#sample.Task#workers OperationStatus.KEYEXIST
            at com.sleepycat.je.SecondaryDatabase.insertKey(SecondaryDatabase.java:887)
            at com.sleepycat.je.SecondaryDatabase.updateSecondary(SecondaryDatabase.java:807)
            at com.sleepycat.je.SecondaryTrigger.databaseUpdated(SecondaryTrigger.java:42)
            at com.sleepycat.je.Database.notifyTriggers(Database.java:1735)
            at com.sleepycat.je.Cursor.putInternal(Cursor.java:1368)
            at com.sleepycat.je.Cursor.putNoOverwrite(Cursor.java:498)
            at com.sleepycat.persist.PrimaryIndex.put(PrimaryIndex.java:366)
            at com.sleepycat.persist.PrimaryIndex.put(PrimaryIndex.java:315)
    Can someone please clarify what my problem is and where I should change for this case study work?

    Thank you

    The above procedure works fine, but when I try to associate the same set of workers with another task I get an exception like:

    The table in this javadoc should help. Please think about whether they are 1 of many, many 1 or many is the appropriate link.

    http://www.Oracle.com/technology/documentation/Berkeley-DB/je/Java/COM/Sleepycat/persist/model/SecondaryKey.html#relate)

    -mark

Maybe you are looking for