ROWNUM in Oracle SQL

rownum is a pseudo column. It numbers the records in a result set. The first record that meets the where criteria in a select statement is given rownum=1, and every subsequent record meeting that same criteria increases rownum.
After issuing a select statement, one of the last steps that oracle does is to assign an increasing (starting with 1, increased by 1) number to each row returned. The value of this row number can always be queried with rownum in a select statement:
select
rownum, column_1, column_2
from
table_1, table_2
where
field_3 = 'some value'
It is important to realize that the first row's rownum is always 1. This implies that the following query won't return a single row:
select 
column_1, column_2
from
table_1, table_2
where
field_3 = 'some value'
and rownum > 5
This is so because the first row would have to meet the following two mutually excluding criterias:
  • rownum is 1
  • rownum is 6 (rownum > 5)
In order to do this query in the (probably) intended spirit, a sub-query must be executed:
select 
column_1, column_2
from (
select
rownum r_, column_1, column_2
from
table_1, table_2
where
field_3 = 'some value'
)
where r_ > 5
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值