Return-Path: <root@fatcity.cts.com>
Received: from newsfeed.cts.com (newsfeed.cts.com [209.68.248.164])
 by naude.co.za (8.11.2/8.11.2) with SMTP id g5L3DGn12552
 for <oracle-l@naude.co.za>; Thu, 20 Jun 2002 23:13:16 -0400
Received: from fatcity.UUCP (uucp@localhost)
 by newsfeed.cts.com (8.9.3/8.9.3) with UUCP id MAA19141;
 Thu, 20 Jun 2002 12:13:04 -0700 (PDT)
Received: by fatcity.com (26-Feb-2001/v1.0g-b71/bab) via UUCP id 0048352D; Thu, 20 Jun 2002 11:53:45 -0800
Message-ID: <F001.0048352D.20020620115345@fatcity.com>
Date: Thu, 20 Jun 2002 11:53:45 -0800
To: Multiple recipients of list ORACLE-L <ORACLE-L@fatcity.com>
X-Comment: Oracle RDBMS Community Forum
X-Sender: Stephane Faroult <sfaroult@oriole.com>
Sender: root@fatcity.com
Reply-To: ORACLE-L@fatcity.com
Errors-To: ML-ERRORS@fatcity.com
From: Stephane Faroult <sfaroult@oriole.com>
Subject: Re: Query Tuning
Organization: Fat City Network Services, San Diego, California
X-ListServer: v1.0g, build 71; ListGuru (c) 1996-2001 Bruce A. Bergman
Precedence: bulk
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
X-MIME-Autoconverted: from 8bit to quoted-printable by newsfeed.cts.com id MAA19141
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by naude.co.za id g5L3DGn12552

Rajesh.Rao@jpmchase.com wrote:
> 
> Hello Folks,
> 
> Given an Oracle 7.3.4 database, how would you  tune a query as under, other
> than suggesting a migration to a higher version. This query is currently
> performing a lot of I/O, obviously doing a full tablescan on CAMPMAIN.
> 
> SELECT CAMPNAME,ASGNMTTYPE,CAMPRTGNUM, LTRIM(RTRIM(CAMPTYPE))
> FROM CAMPMAIN
> WHERE LTRIM(RTRIM(CAMPNAME)) = :b1
> AND (LOAD_FAILED_FLG = 'N'  OR LOAD_FAILED_FLG = ''  OR LOAD_FAILED_FLG IS
> NULL );
> 
> This query runs in a PL/SQL loop. For now, my suggestion was to create a
> temporary table with all the fields and a fully trimmed CAMPNAME field
> outside the loop, create an index on this table, and then use this
> temporary table inside the loop. Any better suggestions?
> 
> Regards
> Raj
> 

1) What the $%ща#? is this LTRIM(RTRIM()) doing? CAMPNAME and CAMPTYPE
are CHAR instead of VARCHAR2 ? You are right to want to clean-up your
data.
2) Queries inside loop are rarely useful. Try to rethink in terms of
INSERT ... SELECT if you are inserting, or UPDATE SET (..., ...   ) =
(SELECT ....) if updating. In-line views can help too. Ah, and if you
are using your SELECT to use the result into another SELECT, there's
something named a join.

-- 
Regards,

Stephane Faroult
Oriole Software
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Stephane Faroult
  INET: sfaroult@oriole.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

