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: Newbie PL/SQL question

Re: Newbie PL/SQL question

From: Rene Nyffenegger <rene.nyffenegger_at_gmx.ch>
Date: 18 Feb 2003 22:58:18 GMT
Message-ID: <b2udq9$1h116d$3@ID-82536.news.dfncis.de>

> 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 today
Received on Tue Feb 18 2003 - 16:58:18 CST

Original text of this message

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