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: Getting the first matching record???

Re: Getting the first matching record???

From: Jerry Apfelbaum <japfelba_at_ican.ca>
Date: 1997/04/09
Message-ID: <334BD97D.DC5E6A75@ican.ca>#1/1

Z. Martinez wrote:
>
> I have a large table (about 4 million rows) that I need to search
> through. Although the query I'm using can result to multiple rows, I
> only need the first matching row. This query will be executed probably
> a hundred thousand times. So I really need to optimize it

SELECT  ......
FROM    ......
WHERE   ......
AND     ROWNUM = 1;

... but be careful. ROWNUM is evaluated before any ORDER BY is done.

Alternately, in PL/SQL, set the query up as a CURSOR. Open the CURSOR and FETCH only 1 row.

-- 
=================================================
Jerry Apfelbaum           email: japfelba_at_ican.ca
Eastern Sun Group Inc.    phone:     416.769.8738 
Toronto, Canada             fax:     416.769.7428
Received on Wed Apr 09 1997 - 00:00:00 CDT

Original text of this message

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