Home > Database > Oracle > How to query the first piece of data in oracle

How to query the first piece of data in oracle

WBOY
Release: 2021-12-27 16:28:54
Original
33740 people have browsed it

In Oracle, you can sort the data and then use rownum and aql nested statements to query the first data. The syntax is "select*from(select*from test order by a)where rownum<2; ".

How to query the first piece of data in oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How does oracle query the first piece of data

It is achieved with the help of rownum. Sorting can be performed in oracle after rownum is added.

Using rownum generally filters part of the rows as the result, so if you sort again, only part of the results are sorted, which may not be the desired result.

If you sort first and then rownum in Oracle, you can use SQL nesting to achieve it. For example,

select * from (select * from test order by a) where rownum<2;
Copy after login

Although this SQL can be implemented, you can query the first 10 data after sorting and modify it according to actual needs. Can.

ROWNUM is a sequence, which is the order in which Oracle database reads data from the data file or buffer. When it obtains the first record, the rownum value is 1, the second record is 2, and so on. If you use >,>=,=,between...and these conditions, because the rownum of the first record obtained from the buffer or data file is 1, it will be deleted, and then remove the record, but it The rownum is still 1, and is deleted again, and so on, and there is no data.

For example, if you want to query the first row of data in the table, you can use the following statement

select * from table where rownum=1 ;
Copy after login

rownum is a sequence that the Oracle database reads from the data file or buffer. order. When it obtains the first record, the rownum value is 1, the second record is 2, and so on.

Recommended tutorial: "Oracle Tutorial"

The above is the detailed content of How to query the first piece of data in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template