var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: alternative of rownum in DB2
Can any body suggest the alternative of oracle rownum in DB2.
I am using rownum for getting the prerequired number of the row froma query.
Select * from tab1 where rownum < 3
The 'fetch first n rows only' doesnt works in stored procedure. So please suggest some other alternative or suggest the use of 'first n rows only' in stored procedure.
Try this out:
SELECT * FROM (SELECT col1,col2,col3, rownumber() over() AS rn FROM tab1) as tr WHERE rn<3;
where col1,col2... will be the column names for tab1 table.
-Prashant G Dahalkar
Rownumber() doesn't work with AND in condition
This query doesn't run if it is appended by AND i.e. if u have more than 1 condition then it doesn't count the number of rows.
SELECT * FROM (SELECT users_id, rownumber() over() AS rn FROM am_customer) as tr WHERE users_id=52612 and rn<3
This doesn't retutn correct no. of records. 'rn' count for primary key values and not number of rows.
Hi vijayanand !
What do you mean by "FETCH FIRST n ROWS ONLY doesn't work in stored procedure. It is !
Can you give more details so I can help ei. how do you create SP, your table struct and sql statement
Re: alternative of rownum in DB2
Originally posted by vijayanand
The 'fetch first n rows only' doesnt works in stored procedure.
Can you please provide the error message and some environment information?
Problems with FETCH FIRST n ROWS ONLY have been known to exist on multiple platforms and have been fixed in various FPs - I am not aware of limitations with SP in general.