Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Newbie PL/SQL question
> The INTO is in the wrong place, though. Try something like the following.
>
> SELECT col1
> INTO my_variable
> FROM ( SELECT col1
> FROM table1
> ORDER BY col2, col3 DESC )
> WHERE rownum = 1;
>
> "Andrew Allen" <andrew.allen_at_handleman.com> wrote in message
> news:3E50FD6C.1020501_at_handleman.com...
As always, when I see a query that can make use of analytical functions, I feel forced to point out to that. In this case, the query would go like
select col1 into my_variable from
( select col1,
row_number() over (order by col2, col3 desc) r
from table1 )
where
r = 1;
Usually, this query should take approx 50% of the time of the one that doesn't use row_number().
Then again, it works only from 8i onwards.
hth
Rene Nyffenegger
-- no sig todayReceived on Tue Feb 18 2003 - 16:58:18 CST