When the Oracle database finds row n (n & gt; = 2), how can we solve the problem that rownum cannot find ?, Oraclerownum

Source: Internet
Author: User

When the Oracle database finds row n (n> = 2), how can we solve the problem that rownum cannot find ?, Oraclerownum

Oracle Database Problems

Rownum cannot be used to query row n (n> = 2 ).

The temporary solution is select * from (select rownum no, ename from emp) where no = 2;, but it is quite troublesome.

The rownum keyword in Oracle Database is special. It is a pseudo field in the query result that indicates the number of rows returned from the query, it can be used to LIMIT the number of rows in the query result (instead of the LIMIT keyword commonly used in Mysql ). However, it cannot be processed as a normal column of data. For example, if you want to find the first data in the table, you can use rownum = 1 to judge it, but you cannot find the second data, this is because when rownum is used to make an equal judgment, it is assumed that the natural numbers above 1 are false. Similarly, if you want to find all the data after the second record, that is, use rownum> 2 to judge the data, Oracle considers it unreasonable. Therefore, you can only search for the nth data. (It looks like it was set up to implement the LIMIT keyword, but I still don't understand why I don't directly set a LIMIT keyword. If you're lucky enough to have a master, please give me some advice, thank you !)

Supplement: when using the order by clause, you cannot directly use rownum to retrieve the first few pieces of data. You have to return the row number in the preceding method !!

These problems will be solved temporarily, and other problems will be updated later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.