Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Fetching last row in oracle

NewLearnerMay 18 2014 — edited May 19 2014

hi all,

I am new to this forum and I have an issue while migrating t-sql to pl-sql.

the Original transact sql is doing a select into. When I wrote the same in pl-sql it is throwing too many rows exception. The query is returning two rows. then I modified the query to restrict the rows returned using the condition rownum<=1. But oracle is returning by default the first row. Where as the transact is returning the last row. So, later the procedures are working on two different rows and my output was different. I found an option to have the same functionality implemented in pl-sql using a sub query. But is there any optimized way to handle this is my question. Also I cannot do an order by On a column as I don't know the clients business logic on which column the order by to be implemented. I tried using order by rownum and rownum<=1 By writing a sub query. But I was told that it would be a performance overhead. is there any optimized way to fetch the last row in oracle. Pls help

regards,

Sona

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2014
Added on May 18 2014
37 comments
23,407 views