Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Getting the first row from a select
> >>> select * from COMPANY where COMPANY_NAME >= 'whatever' and ROWNUM = 1
order
> >>> by COMPANY_NAME;
This query (without the ROWNUM = ) will open a cursor and retrieve all of the rows in the result set. If you want only the first row of a sorted result set you have two possible solutions in Oracle.
OPEN CURSOR my_cursor FETCH my_cursor INTO variable_company_name . . .; CLOSE CURSOR;
BTW, SELECT * can get your code into trouble if you later add or remove columns from a table, or rebuild the table and the order of the columns changes. Always explicitely declare the columns in the SELECT list.
Hope this helps.
-- Don Holliday -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your OwnReceived on Fri Oct 02 1998 - 00:00:00 CDT