Rownum:根据sql查询出的结果集为每行分配一个逻辑编号,能够动态的变化,根据sql每次的查询变化进行重新的编号,每次都是从1开始排号;
Rowid:在数据产生时就会有一个唯一的标示,这个标示类似于物理结构上的物理记录,是不会随着sql的查询发生变化的。
例如:selectrowid,rownum,t.order_id from tab_order_s t where t.contract_type=41;
得出结果:
对于rowid的标示不容置疑,关于rownum应用需要注意几点:
Conditions testing for ROWNUMvalues greater than a positive integer are always false.
Forexample, this query returns no rows: SELECT * FROM employees WHERE ROWNUM >1;
Thefirst row fetched is assigned a ROWNUM of 1 and makes the condition false. The
secondrow to be fetched is now the first row and is also assigned a ROWNUM of 1 and
makesthe condition false. All rows subsequently fail to satisfy the condition, so no
rows arereturned.
大体意思:Rownum在每次生成的时候是从1开始排序的。
例如:
Select * from tab_order_s twhere rownum>2; à错误
Select * from tab_order_s twhere rownum<=10; à正确