Order by in cursor [message #322496] |
Fri, 23 May 2008 14:37  |
chintu00
Messages: 91 Registered: February 2007 Location: NJ, US
|
Member |
|
|
I have seen people writing cursors where they use an order by clause. What could possibly be the use/misuse of order by in a cursor expect for slowing down the process.
Unless if the cursor fetches N rows and want to do something with first N/2 row and something else with the remaining N/2 rows and so on.
order by performs sort operation and can be expensive where the cursor fetches large number of records.
|
|
|
|
|
|
|
Re: Order by in cursor [message #322590 is a reply to message #322519] |
Sat, 24 May 2008 11:57   |
chintu00
Messages: 91 Registered: February 2007 Location: NJ, US
|
Member |
|
|
So Michel, what you are saying is that order by clause is useful when we know the kind of data in the table and expect to reach the required record from cursor record set quickly by sorting so we don't have to loop through more number of records.Though I feel it is a special case.
|
|
|
|
|
|
Re: Order by in cursor [message #323164 is a reply to message #322590] |
Tue, 27 May 2008 09:08  |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
If you were (for example) producing statements of a customers transactions, for all customers, wouldn't it make sense to order the transactions cursor by customer id and transaction date?
There are many, many times when the order that data is returned in is either useful or important.
|
|
|