现在想在informix中实现oracle的rownum方法。 例如: select rownum from test ;返回: 1 2 3 4 5
烙印99
浏览 366回答 2
2回答
梵蒂冈之花
可以用来进行全前N条记录,或者分页操作。Oracle SQL如下:select * from sometable where rownum <= 100; select * from sometable where rownum > 100 and rownum <= 200; SELECT * FROM ( SELECT A.*,ROWNUM AS RN FROM (SELECT * FROM sometable order by col) A WHERE ROWNUM <= 200) T WHERE T.RN > 100Informix 有更简单、高效的分页功能: select first 100 * from sometable; select skip 100 first 100 * from sometable; select skip 100 first 100 * from sometable order by col;记录编号:在ORACLE中,可以直接通过rownum 得到每条记录的一个编号,select rownum, * from sometable ; Informix中需要通过创建一个存储过程来实现类似功能。 CREATE FUNCTION rownum () returning int as rownum; define global counter int default 0; let counter = counter + 1; return counter; end function; CREATE PROCEDURE init_rownum (); define global counter int default 0; let counter = 0; end procedure; 可以按如下方式使用函数反问记录编号。