Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: instead of SELECT TOP: cursors or nested queries?
Diego wrote:
> I'm using Oracle 9i. I need an equivalent of Sql Server's SELECT TOP
> with ORDER BY.
> I have found two different approaches to do this.
> 1- Declaring a cursor and fetching the rows I need.
> 2- Using a nested query to order the table in the inner select and
> rownum in the outer.
>
> Both solutions work right, but I want to know which has a better
> performance when my tables become large, i.e. more than 10K records.
> I guess that if I create an index on the column I order by there
> should be no significant differences in performance between those
> solutions, but I'm not sure.
>
> Can anybody give some advice?
10K records is hardly large and nothing beats testing which is exactly what you should do. It couldn't take more than 5 minutes to build a table with 50,000 rows and find out.
But my gut would be the in-line view will almost always outperform the cursor.
-- Daniel Morgan http://www.outreach.washington.edu/ext/certificates/oad/oad_crs.asp http://www.outreach.washington.edu/ext/certificates/aoa/aoa_crs.asp damorgan_at_x.washington.edu (replace 'x' with a 'u' to reply)Received on Thu Jan 08 2004 - 09:50:12 CST
![]() |
![]() |