Solved

Update set of records in Oracle

Posted on 2014-03-03
1
434 Views
Last Modified: 2014-03-10
I need to update a set of records in Oracle but to do so I need to join two tables to get the exact records that I need to update.  I am trying this statement but getting a non-preserved key error.

I have attached the update statement (note the tables and field names are changed to keep information confidential)update-records.txt
0
Comment
Question by:gilnari
1 Comment
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39902284
UPDATE employee ep
   SET reported_name = 'XYZ'
 WHERE ep.state LIKE 'ACME'
   AND table_name LIKE 'EMPLOYEE'
   AND ep.county LIKE 'ACME'
   AND EXISTS
           (SELECT NULL
              FROM versions v
             WHERE ep.name = v.name AND ep.version = v.version);


"table_name" wasn't aliased so I don't know if it was from employee or versions.
Simply move that condition to the EXISTS subquery if it applies to versions.

Also,  your "LIKE" conditions don't have wildcards.  So those should probably be equalities instead.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle RAC 12c 8 87
SQL query question 8 92
Extract Currency data from a string and put them in a new field 3 42
Oracle Distributed Transaction Lock Error ORA-01591 8 52
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question