Solved

Update Query returine more then one row in Oracle

Posted on 2014-04-21
4
375 Views
Last Modified: 2014-04-25
I need update all values on one table as T where there exist certain condition on other table.

I know this query is wrong but how do I get it to work in Oracle update statement if the select statement between () returns a value

update sample s set s.L_INVOICE_FLAG  = 'T' where (s.project like (select p.name from project p inner join sample s on p.name = s.project where p.closed = 'T' and p.status = 'V'))
0
Comment
Question by:gilnari
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
Not sure I follow the logic but try IN.

Change:
...  where (s.project like (select p.name ...
to:
...  where (s.project in (select p.name ...
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
and then also remove the inner join as it won't be required
UPDATE sample s
SET s.L_INVOICE_FLAG = 'T'
WHERE s.project IN (
		SELECT p.NAME
		FROM project p
		WHERE p.closed = 'T' AND p.STATUS = 'V'
		)

Open in new window

0
 

Expert Comment

by:sunnyboyxjx
Comment Utility
... where (s.project like ...
and
... on p.name = s.project  ...
are duplicated.
So it should be like this:
update sample s set s.L_INVOICE_FLAG  = 'T' where s.project in (select p.name from project p where p.closed = 'T' and p.status = 'V')
you can not use 'like' against sub-query.
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
@sunnyboyxjx
did I not propose exactly the same query?
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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

771 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

10 Experts available now in Live!

Get 1:1 Help Now