Re: UPDATE query problem
- From: sybrandb@xxxxxxxxx
- Date: Sat, 30 Jun 2007 10:38:57 +0200
On Fri, 29 Jun 2007 22:04:57 -0400, "Syltrem"
<syltremzulu@xxxxxxxxxxxx> wrote:
Update MYTABLE
set DESCRIPTION = (select DESCRIPTION from MYTABLE where
MYTABLE.KEYVAL=(select XREF.KEYVAL2 from XREF where
XREF.KEYVAL1=MYTABLE.KEYVAL)),
set HELPTEST = (select HELPTEXT from MYTABLE where MYTABLE.KEYVAL=(select
XREF.KEYVAL2 from XREF where XREF.KEYVAL1=MYTABLE.KEYVAL))
where MYTABLE.KEYVAL=XREF.KEYVAL1
(something like this I think, I would have to find good alias names to get
it to work)
What if I had 20 columns to update like this, I need to have 20 subqueries,
each reading the exact same row? Is there a more efficient way of doing
this?
The correct syntax for this UPDATE statement =
update mytable
set (description, helptext ) =
(select description,helptext
from mytable
where mytable.keyval in (select xref.keyval2 from xref where
xref.keyval1 = mytable.keyval))
I see only 1 subquery.
If you have bad design, then fix the design.
Other than, maybe you can use the WITH statement introduced in 9i.
Do NOT convert this into PL/SQL: whatever you do, you CAN do it use
SQL, and using SQL won't involve context switches, so you should do it
in SQL.
--
Sybrand Bakker
Senior Oracle DBA
.
- Follow-Ups:
- Re: UPDATE query problem
- From: Urs Metzger
- Re: UPDATE query problem
- References:
- UPDATE query problem
- From: Syltrem
- Re: UPDATE query problem
- From: hpuxrac
- Re: UPDATE query problem
- From: Syltrem
- UPDATE query problem
- Prev by Date: Re: primary key & nlssort
- Next by Date: Re: .NET CF
- Previous by thread: Re: UPDATE query problem
- Next by thread: Re: UPDATE query problem
- Index(es):
Relevant Pages
|