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; ".
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;
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 ;
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!