Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Are these suppose to be equivalent?

RE: Are these suppose to be equivalent?

From: Powell, Mark D <mark.powell_at_eds.com>
Date: Tue, 28 Sep 2004 12:54:11 -0400
Message-ID: <564DE4477544D411AD2C00508BDF0B6A2133DF12@usahm018.exmi01.exch.eds.com>


The first update is missing the where clause that should exist to limit the rows affected by the update to only those rows that have a corresponding row in the update subquery. Rows in the target table without a match will have the target column nullified. This is a common newbie error. Even if a 1:1 relationship is specified in the application specification unless there is a constraining mechanism in place in the database the SQL should not reply on the relationship. Even with a constraining mechanism in place it is best to write SQL such that it explicitly targets the desired row set. This makes the desired result clear to readers of the code who may not be aware of all the system design features.

IMHO -- Mark D Powell --

-----Original Message-----
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org]On Behalf Of Stephen.Lee_at_DTAG.Com Sent: Tuesday, September 28, 2004 12:36 PM To: jkstill_at_gmail.com
Cc: oracle-l_at_freelists.org
Subject: RE: Are these suppose to be equivalent?

I think there is a 1:1 relation. On the surface, based on what I know about SQL, it would seem that if the subquery returns one value, then all columns of planb_location would be set to that value; if the subquery returns multiple values, the result should be an error(??). But there is no error. It works, and the updates correspond correctly. So clearly, Oracle is keeping the rows that match up "inside" the subquery properly matched up "outside" the subquery. And now we are back to the whole issue of whether there is an official inside and outside of the subquery. That is: Is the update with the subquery SUPPOSED to work, or does it just happen to work because of some subquery magic applied by Oracle.

>-----Original Message-----
>It would appear that statement #2 should update a subset of the data
>that statement #1 is updating.
>
>One exception would be if there is a 1:1 relation between location
>and planb_location.

--
http://www.freelists.org/webpage/oracle-l

--
http://www.freelists.org/webpage/oracle-l
Received on Tue Sep 28 2004 - 11:50:54 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US