Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Newbie PL/SQL question
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 )
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 AllenReceived on Mon Feb 17 2003 - 10:14:48 CST
![]() |
![]() |