Print Thread
Rownum on a client side
#4164 11/22/02 02:54 PM
Joined: Jun 2000
Posts: 25
Moscow, Russia
D
Member
OP Offline
Member
D
Joined: Jun 2000
Posts: 25
Moscow, Russia
My users want to have a column that shows row number (mostly for export in MS Excel). ROWNUM on server side does not work with ORDER BY. Is there a way to make it? May be calculated field some how?


Dmitri
Re: Rownum on a client side
#4165 11/22/02 06:56 PM
Joined: Dec 2000
Posts: 31
MA, USA
B
Member
Offline
Member
B
Joined: Dec 2000
Posts: 31
MA, USA
I forget what version of Oracle you can do this in (starting with 8.0?) but you can get rownum to work after an 'order by' by making the query an 'inline view' and using rownum on the outside part. Here's an example:

select rownum, t.* from (select * from emp order by ename) t;

Good luck!

Mark Ford
Benthic Software


Mark Ford
Benthic Software
Re: Rownum on a client side
#4166 11/25/02 12:19 PM
Joined: Jun 2000
Posts: 25
Moscow, Russia
D
Member
OP Offline
Member
D
Joined: Jun 2000
Posts: 25
Moscow, Russia
I have Oracle 8.0.6 and can not use order by in the subquery. IMHO it should be done on client side but I don't know how.


Dmitri
Re: Rownum on a client side
#4167 11/25/02 11:08 PM
Joined: Aug 1999
Posts: 22,220
Member
Offline
Member
Joined: Aug 1999
Posts: 22,220
I'm not sure I understand the logic of an "order by rownum" concept. A rownum is not a property of a record in a table, but the sequence number of a record in a result set. The rownum of each record in a result set depends on the order by clause and where clause that you are using.

What should the order be when you order by rownum?

------------------
Marco Kalter
Allround Automations


Marco Kalter
Allround Automations
Re: Rownum on a client side
#4168 11/26/02 12:28 PM
Joined: Jun 2000
Posts: 25
Moscow, Russia
D
Member
OP Offline
Member
D
Joined: Jun 2000
Posts: 25
Moscow, Russia
All
I solved it. I created Calculated field RN and in OnCalculate()
[quote]
Code
    qexportRN->AsInteger=qexport->RecNo;    
[/quote]


Dmitri
Re: Rownum on a client side
#4169 11/27/02 02:42 AM
Joined: Dec 2000
Posts: 31
MA, USA
B
Member
Offline
Member
B
Joined: Dec 2000
Posts: 31
MA, USA
Sounds like the order by in a subquery must have been added in 8.1. Marco, the rownum gets assigned before the order by statement is processed in Oracle. So it is quite easy to do a query where the rownum comes back out of order (boy, was I surprised the first time I saw that!) They fixed it by allowing order by in an inline view (which works very well.)

-Mark Ford


Mark Ford
Benthic Software

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.037s Queries: 14 (0.012s) Memory: 2.5162 MB (Peak: 3.0394 MB) Data Comp: Off Server Time: 2024-05-16 22:50:55 UTC
Valid HTML 5 and Valid CSS