update statement using from clause [message #648208] |
Thu, 18 February 2016 09:10 |
|
MurraySobol
Messages: 5 Registered: February 2016 Location: Kitchener ON
|
Junior Member |
|
|
Does Oracle support this form of an UPDATE statement:
update tablea
set column =
(select value
from tableb
where conditions match
)
from tablea
where other conditions
The above is a "generic" version of the script.
|
|
|
Re: update statement using from clause [message #648209 is a reply to message #648208] |
Thu, 18 February 2016 09:13 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
MurraySobol wrote on Thu, 18 February 2016 15:10Does Oracle support this form of an UPDATE statement:
update tablea
set column =
(select value
from tableb
where conditions match
)
from tablea
where other conditions
The above is a "generic" version of the script.
I've highlighted the syntax error.
|
|
|
|
Re: update statement using from clause [message #648291 is a reply to message #648209] |
Fri, 19 February 2016 13:16 |
|
MurraySobol
Messages: 5 Registered: February 2016 Location: Kitchener ON
|
Junior Member |
|
|
Here is my update statement:
UPDATE s1_vehicle_processing
SET s1_vehicle_processing.schedule_code =
(SELECT s1_release.schedule_code
FROM s1_release,
s1_contract
WHERE s1_release.contract_nbr = vp.contract_nbr
AND s1_release.release_nbr = vp.release_nbr
AND s1_release.contract_nbr = s1_contract.contract_nbr
AND s1_contract.pricing_type_code <> 'HLD'
)
FROM s1_vehicle_processing vp,
s1_contract c
WHERE vp.contract_nbr = c.contract_nbr
AND c.pricing_type_code <> 'HLD'
AND vp.schedule_code IS NULL
/
and here is the error I get:
Error starting at line : 1 in command -
UPDATE s1_vehicle_processing
SET s1_vehicle_processing.schedule_code =
(SELECT s1_release.schedule_code
FROM s1_release,
s1_contract
WHERE s1_release.contract_nbr = vp.contract_nbr
AND s1_release.release_nbr = vp.release_nbr
AND s1_release.contract_nbr = s1_contract.contract_nbr
AND s1_contract.pricing_type_code <> 'HLD'
)
FROM s1_vehicle_processing vp,
s1_contract c
WHERE vp.contract_nbr = c.contract_nbr
AND c.pricing_type_code <> 'HLD'
AND vp.schedule_code IS NULL
Error at Command Line : 11 Column : 3
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
I don't believe that Oracle supports this type of SQL syntax, at least not in Oracle 11g
Murray
[Edit MC: add and fix code tags]
[Updated on: Fri, 19 February 2016 13:20] by Moderator Report message to a moderator
|
|
|
|
|
|
|
Re: update statement using from clause [message #648299 is a reply to message #648298] |
Fri, 19 February 2016 15:32 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Well, perhaps. But it doesn't sense make to apply a FROM clause to an UPDATE statement. Whereas this structure makes perfect sense, and is what OP should be using:orclz>
orclz> update emp set ename=(select loc from dept where deptno=10) where comm is null;
10 rows updated.
orclz>
|
|
|
|
Re: update statement using from clause [message #648301 is a reply to message #648300] |
Fri, 19 February 2016 16:17 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
What horrible syntax that third one is. I hope it isn't part of the ANSI standard.
Well, that's all from me for a while. I'm off to Lindbergh Field shortly. Goodbye, Del Mar! As close to paradise as one is likely to get.
|
|
|
Re: update statement using from clause [message #648386 is a reply to message #648301] |
Mon, 22 February 2016 14:57 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
Try the following
UPDATE S1_vehicle_processing Vp
SET S1_vehicle_processing.Schedule_code =
(SELECT S1_release.Schedule_code
FROM S1_release, S1_contract
WHERE S1_release.Contract_nbr = Vp.Contract_nbr
AND S1_release.Release_nbr = Vp.Release_nbr
AND S1_release.Contract_nbr = S1_contract.Contract_nbr
AND S1_contract.Pricing_type_code <> 'HLD')
WHERE EXISTS
(SELECT NULL
FROM S1_contract C
WHERE Vp.Contract_nbr = C.Contract_nbr
AND C.Pricing_type_code <> 'HLD')
AND Vp.Schedule_code IS NULL;
|
|
|
|
|
Re: update statement using from clause [message #648550 is a reply to message #648517] |
Thu, 25 February 2016 04:31 |
|
varlamovvp
Messages: 13 Registered: February 2016 Location: Russia
|
Junior Member |
|
|
Hi! I'm not sure, but maybe it will help you
MERGE into S1_vehicle_processing tu
USING (
SELECT r.schedule_code, vp.rowid as rwd
FROM s1_release r, s1_contract c, s1_vehicle_processing vp
WHERE r.contract_nbr = vp.contract_nbr
AND r.release_nbr = vp.release_nbr
AND r.contract_nbr = c.contract_nbr
AND vp.contract_nbr = c.contract_nbr
AND c.pricing_type_code <> 'HLD'
AND vp.schedule_code IS NULL
) t
ON
( tu.rowid=t.rwd )
WHEN MATCHED THEN UPDATE SET tu.schedule_code=t.schedule_code
;
|
|
|