Java code
Select t. *, t. rowid, rownum from test1 t
Name KM CJ ROWID ROWNUM
Zhang San Language 80 AAAHhOAALAAATSIAAA 1
James math 86 AAAHhOAALAAATSIAAB 2
James 75 AAAHhOAALAAATSIAAC 3
Li Si language 79 AAAHhOAALAAATSIAAD 4
Li Si math 85 AAAHhOAALAAATSIAAE 5
Li Si English 78 AAAHhOAALAAATSIAAF 6
Java code
Select t. *, t. rowid, rownum from test1 t where rownum <3 order by CJ
Zhang San Language 80 AAAHhOAALAAATSIAAA 1
James math 86 AAAHhOAALAAATSIAAB 2
The nested method can be used successfully.
Java code
Select t. *, t. rowid, rownum from (select * from test1 t order by CJ) t where rownum <3
James 75 AAAHhOAALAAATSIAAF 1
Li Si English 78 AAAHhOAALAAATSIAAF 2
However, nesting affects efficiency. What if it is not nested?
If you do not define a primary key or a field that can uniquely identify a record, rowid is used to uniquely identify the record,
Rowid will not change, but if your table changes the tablespace, rowid may also change.
However, if you set the CJ field as the primary key, run
Java code
Select t. *, t. rowid, rownum from test1 t where rownum <3 order by CJ
James 75 AAAHhOAALAAATSIAAC 1
Li Si English 78 AAAHhOAALAAATSIAAF 2