Introduction to rowid and rownum in Oracle

Source: Internet
Author: User

Q: Does Oracle differentiate ROWID from ROWNUM? If they have differences, what are their differences?

A: Just as your address uniquely identifies your location, an oracle rowid uniquely identifies the physical address of a piece of data.
Rowid provides all the information you need to find this row of data, hard disk number, cylinder, block and the offset address on the block.
Rownum is a pseudo code, a placeholder that you can reference in SQL * Plus. Rownum can be used to write professional SQL statements and adjust SQL statements.

Note the following when using rownum in SQL statements:
Correct: where rownum <n;
Where rownum = 1;
Error: where rownum> n;
Where rownum = some_num> 1
This is correct if you have:
Select * from (
Select rownum rn, t. * from t
)
Where rn = 3;

For example, to display the first five pieces of data, you can use rownum as a filter:
SQL> select rownum, emp. empno, emp. ename, emp. job from emp
2 where rownum <= 5;

ROWNUM EMPNO ENAME JOB
----------------------------------
1 7369 SMITH CLERK
2 7499 ALLEN SALESMAN
3 7521 WARD SALESMAN
4 7566 JONES MANAGER
5 7654 MARTIN SALESMAN

In short, the difference between rowid and rownum is that rownum is temporary while rowid is permanent.
In addition, rowid can be used to obtain a data row. rowid is meaningful only in the content of a single SQL statement. It is a way to retrieve a dataset by reference.

SQL> select rownum, rowid, empno, initcap (ename), initcap (job), sal from emp;

Rownum rowid empno initcap (ENAME) INITCAP (JOB) SAL
--------------------------------------------------------------------
1 AAAL + ZAAEAAAAAdAAA 7369 Smith Clerk 800.00
2 AAAL + ZAAEAAAAAdAAB 7499 Allen Salesman 1600.00
3 AAAL + ZAAEAAAAAdAAC 7521 Ward Salesman 1250.00
4 AAAL + ZAAEAAAAAdAAD 7566 Jones Manager 2975.00
5 AAAL + ZAAEAAAAAdAAE 7654 Martin Salesman 1250.00
6 AAAL + ZAAEAAAAAdAAF 7698 Blake Manager 2850.00
7 AAAL + ZAAEAAAAAdAAG 7782 Clark Manager 2450.00
8 AAAL + ZAAEAAAAAdAAH 7788 Scott Analyst 3000.00
9 AAAL + ZAAEAAAAAdAAI 7839 King President 5000.00
10 AAAL + ZAAEAAAAAdAAJ 7844 Turner Salesman 1500.00
11 AAAL + ZAAEAAAAAdAAK 7876 Adams Clerk 1100.00
12 AAAL + ZAAEAAAAAdAAL 7900 James Clerk 950.00
13 AAAL + ZAAEAAAAAdAAM 7902 Ford Analyst 3000.00
14 AAAL + ZAAEAAAAAdAAN 7934 Miller Clerk 1300.00

Related Article

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.