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: Brian E Dick <bdick_at_cox.net>
Date: Tue, 18 Feb 2003 19:28:06 GMT
Message-ID: <aPv4a.34123$4F3.2000431@news2.east.cox.net>


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...
>
>
> mobiGeek wrote:
> > I am new to PL/SQL. I am trying to get the first row from a SELECT
> > result set, but am not sure how to go about it.
> >
> > In ASA, I can do:
> >
> > SELECT FIRST col1
> > INTO @my_variable
> > FROM table1
> > ORDER BY col2, col3 DESC
> >
> > This will get the value of "col1" from the FIRST row in the result
> > set.
> >
> > How can I go about this in PL/SQL ?
> SELECT col1
> FROM ( SELECT col1
> INTO my_variable
> FROM table1
> ORDER
> BY col2, col3 DESC )
> WHERE rownum = 1;
>
> The inline view is necessary because you have to sort your data before
> constraining the number of rows to return. Oracle, IIRC, assigns the
> row number before sending the result set to sort so you have to make
> sure that you sort first.
> --
> Andrew Allen
>
Received on Tue Feb 18 2003 - 13:28:06 CST

Original text of this message

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