ROWNUM in Oracle SQL
2008-04-18 01:40
239 查看
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:
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:
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:
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
相关文章推荐
- Named system exception in Oracle - Predefined PL/SQL Exceptions
- Testing/Running the stored procedure(has OUT params) in Oracle sqldeveloper or sqlplus
- [Oracle Misc] Varchar2 in SQL and PL/SQL, etc
- Methods of quick exploitation of blind SQL Injection Vulnerabilities in Oracle
- Oracle SQL in 超过1000 的解决方案
- 在Oracle SQL中取数据时有时要用到in 和 exists 那么他们有什么区别呢?
- How to Write A Better SQL Statement in Oracle
- Oracle SQL 跟踪 --- dbms_system.set_sql_trace_in_session
- oracle_SQL中ROWID与ROWNUM的使用
- START WITH and CONNECT BY in Oracle SQL
- 040908 R Oracle & SqlServer 's ORDER -->select top & where rownum <= 3
- ORACLE中用rownum分页并排序的SQL语句
- Advanced Oracle SQL: Subquery Inline View
- Data Types with Different Maximum Sizes in oracle PL/SQL and SQL
- What does a (+) sign mean in an Oracle SQL WHERE clause?
- ORACLE中用rownum分页并排序的SQL语句
- ygfmobileORACLE中用rownum分页并排序的SQL语句
- oracle利用INLIST ITERATOR优化SQL
- Oracle operate XML in SQL
- ORACLE中用ROWNUM分页并排序的SQL语句