Home » SQL & PL/SQL » SQL & PL/SQL » sql query (oracle 10g)
sql query [message #386742] Mon, 16 February 2009 22:29 Go to next message
rajasekhar857
Messages: 500
Registered: December 2008
Senior Member
hi,
is it possible to write update with select statement like we are using insert with select statement.
Re: sql query [message #386744 is a reply to message #386742] Mon, 16 February 2009 22:35 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
So we can help you & please be consistent & correct in your postings.


Yes, if you are willing to Read The Fine Manual.
Re: sql query [message #386748 is a reply to message #386742] Mon, 16 February 2009 23:01 Go to previous messageGo to next message
ecearund
Messages: 5
Registered: February 2009
Location: Bangalore
Junior Member
Hi,
Yes you can you can use SELECT statement as a subquery for updating a some columns in UPDATE statement..

Here some examples for u...

1)
UPDATE Table1
SET Table1(col1) = (SELECT Table2(col1)
FROM Table2
WHERE some condition);


2)
UPDATE Table1
SET Table1(col1)='xxxxxxxxxx'
WHERE Table1(col2)=
(
SELECT ab.Table2(col2)
FROM Table1 a, Table2 ab
WHERE a.Table1(col3)=ab.Table2(col3)
);

3)
UPDATE Table1
SET Table1(col1) = ( SELECT Table2.col1
FROM Table2
WHERE Table2.col2 = Table1.col2)
WHERE EXISTS
( SELECT Table2.col1
FROM Table2
WHERE Table2.col2 = Table1.col2);
Re: sql query [message #386799 is a reply to message #386742] Tue, 17 February 2009 00:54 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL Reference, UPDATE

@ecearund,
Your statements are not valid.

Regards
Michel
Re: sql query [message #388110 is a reply to message #386742] Mon, 23 February 2009 04:33 Go to previous message
ashoka_bl
Messages: 398
Registered: November 2006
Location: Bangalore
Senior Member

Hi,

Can you post whatever you tried ? were you able to execute, you got the results ? or the query failed ?

If i assume that this is what you are looking for,

UPDATE emp
   SET sal = (SELECT max (sal)
                FROM emp)
 WHERE empno = 7369


Then it will dfntly execute.

Also refer http://www.psoug.org/reference/update.html
And some other Examples,

Do post what you tried.

Regards,
Ashoka BL
Bengaluru
Previous Topic: Rearrange column values
Next Topic: function & wrap utility (merged)
Goto Forum:
  


Current Time: Thu Dec 08 10:17:12 CST 2016

Total time taken to generate the page: 0.05947 seconds