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

Home -> Community -> Usenet -> c.d.o.misc -> Re: General SQL statement question

Re: General SQL statement question

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Mon, 16 May 2005 16:50:09 +0200
Message-ID: <chch81500a96tl8uf3d3h4j726v9uofn98@4ax.com>


On 16 May 2005 07:37:21 -0700, dutilr_at_netscape.net wrote:

>You'll have to excuse me, but I'm a little light on my SQL skills. Can
>anyone tell me if the following SQL query should work or not? It has 4
>files, but the first file isn't linked to any of the other three files
>in the WHERE clause. I don't get it. Am I just missing something?
>Please let me know if you have any thoughts or suggestions.
>
>insert into cs02p10w
>SELECT DISTINCT a.csnwpl,d.opcatn,d.oppric
>FROM cs01p10w a, opprltp d,mspmj200 e, cs03p100 g
>WHERE d.opplst=&PL
> and d.opcatn=e.prdno
> and integer('0'||e.uprgrp)=g.cspgrp
> and d.oppric<>0
> and (substr(e.ubusut,1,1) between 'A' and 'H' or e.ubusut like 'M%' )
> and e.ubusut||e.ufamly<>'M O ' with NC

It might work, but the performance will be abysmal. Without the distinct you will be getting a cartesian product of a, and the join of the other three tables. If you have two sets, and the number of elements of the first set is a and the number of the second set is b, the cartesian product will consist of a x b elements. The distinct is just a trick to make the result set unique again. Apart from that, AFAIK, there is no integer function in Oracle, and even if there would be, it would preclude the use of any index on that column.
In short: this statement is horrible.

--
Sybrand Bakker, Senior Oracle DBA
Received on Mon May 16 2005 - 09:50:09 CDT

Original text of this message

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