Solved

Update set of records in Oracle

Posted on 2014-03-03
1
423 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 73

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.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now