How to use oracle rowid

Source: Internet
Author: User

How to use oracle rowid

1. Create a temporary table
Create table test_rowid (id number, row_id rowid );
2. Insert a row of records
Insert into test_rowid values (1, null );
3. Modify the inserted record
Update test_rowid set row_id = rowid where id = 1;
4. View rowid
Select rowid, row_id from test_rowid;
The returned result is:
Rowid row_id
AAAO0DAAJAAAAMYAAA AAAO0DAAJAAAAMYAAA

Oracle's physical extended ROWID has 18 bits, each of which uses 64-bit encoding, respectively using ~ Z, ~ Z, 0 ~ 9, +,/represents a total of 64 characters. A Indicates 0, B Indicates 1 ,...... Z indicates 25, a indicates 26 ,...... Z indicates, 0 indicates 52 ,......, 9 indicates 61, + indicates 62,/indicates 63.

ROWID can be divided into four parts.

(1). OOOOOO: the first six digits represent the data object number. After converting the NUMBER, match the DATA_OBJECT_ID in DBA_OBJECTS to determine the table information.

In the preceding example, the data object number is AAAO0D, and the conversion bit NUMBER is 14 × 64 × 64 + 52 × 64 + 3.
Enter the following query:
Select owner, object_name from dba_objects where data_object_id = 14*64*64 + 52*64 + 3;
Return Value:
OWNER OBJECT_NAME
WG TEST_ROWID
(2) FFF: 7th to 9 digits indicate the data file number of the relative tablespace.
In the preceding example, AAJ indicates data file 9.
Enter the following query:
(3). BBBBBB: 10th to 15 digits indicates the BLOCK number of the record in the data file.

The above example is AAAAMY. The conversion bit number is 12 × 64 + 24, which indicates the 792nd blocks of the record in the data file.

(4). RRR: the last three digits indicate the number of records in the BLOCK.

The above example is AAA, indicating 0th records (always counted from 0 ).

Iv. References

1. oracle rowid
2. Analysis of basic Oracle data storage formats (iv) -- ROWID Type (I)
3. Why does the oracle data file have Rfile # and file #

SQL> CREATE TABLE EMP (EMPNO NUMBER (4) NOT NULL,
2 ENAME VARCHAR2 (10 ),
3 JOB VARCHAR2 (9 ),
4 mgr number (4 ),
5 hiredate date,
6 sal number (7, 2 ),
7 comm number (7, 2 ),
8 deptno number (2 ));

Table created.

SQL>
SQL> INSERT INTO EMP VALUES (7369, 'Smith ', 'cler', 7902, TO_DATE ('17-DEC-1980', 'dd-MON-YYYY '), 800, NULL, 20 );

1 row created.

SQL> INSERT INTO EMP VALUES (7499, 'allen', 'salesman', 7698, TO_DATE ('20-FEB-1981 ', 'dd-MON-YYYY'), 1600,300, 30 );

1 row created.

SQL> INSERT INTO EMP VALUES (7521, 'ward ', 'salesman', 7698, TO_DATE ('22-FEB-1981', 'dd-MON-YYYY '), 1250,500, 30 );

1 row created.

SQL> INSERT INTO EMP VALUES (7566, 'Jones ', 'manager', 7839, TO_DATE ('2-APR-1981', 'dd-MON-YYYY '), 2975, NULL, 20 );

1 row created.

SQL> INSERT INTO EMP VALUES (7654, 'martin ', 'salesman', 7698, TO_DATE ('28-SEP-1981', 'dd-MON-YYYY '), 1250,140 0, 30 );

1 row created.

SQL> INSERT INTO EMP VALUES (7698, 'bucke', 'manager', 7839, TO_DATE ('1-MAY-1981 ', 'dd-MON-YYYY'), 2850, NULL, 30 );

1 row created.

SQL> INSERT INTO EMP VALUES (7782, 'clark', 'manager', 7839, TO_DATE ('9-JUN-1981 ', 'dd-MON-YYYY'), 2450, NULL, 10 );

1 row created.

SQL> INSERT INTO EMP VALUES (7788, 'Scott ', 'analyst', 7566, TO_DATE ('09-DEC-1982', 'dd-MON-YYYY '), 3000, NULL, 20 );

1 row created.

SQL> INSERT INTO EMP VALUES (7839, 'King', 'President ', NULL, TO_DATE ('17-NOV-1981', 'dd-MON-YYYY '), 5000, NULL, 10 );

1 row created.

SQL> INSERT INTO EMP VALUES (7844, 'turner ', 'salesman', 7698, TO_DATE ('8-SEP-1981', 'dd-MON-YYYY '), 1500, 0, 30 );

1 row created.

SQL> INSERT INTO EMP VALUES (7876, 'adams', 'cler', 7788, TO_DATE ('12-JAN-1983 ', 'dd-MON-YYYY'), 1100, NULL, 20 );

1 row created.

SQL> INSERT INTO EMP VALUES (7900, 'James ', 'cler', 7698, TO_DATE ('3-DEC-1981', 'dd-MON-YYYY '), 950, NULL, 30 );

1 row created.

SQL> INSERT INTO EMP VALUES (7902, 'Ford ', 'analyst', 7566, TO_DATE ('3-DEC-1981', 'dd-MON-YYYY '), 3000, NULL, 20 );

1 row created.

SQL> INSERT INTO EMP VALUES (7934, 'miller ', 'cler', 7782, TO_DATE ('23-JAN-1982', 'dd-MON-YYYY '), 1300, NULL, 10 );

1 row created.

SQL>
SQL> CREATE TABLE DEPT (DEPTNO NUMBER (2), DNAME VARCHAR2 (14), LOC VARCHAR2 (13 ));

Table created.

SQL>
SQL> INSERT INTO DEPT VALUES (10, 'accounting', 'New YORK ');

1 row created.

SQL> INSERT INTO DEPT VALUES (20, 'Research ', 'Dallas ');

1 row created.

SQL> INSERT INTO DEPT VALUES (30, 'sales', 'Chicago ');

1 row created.

SQL> INSERT INTO DEPT VALUES (40, 'operations', 'boston ');

1 row created.

SQL>
SQL> select rowid from emp
2 intersect
3 select rowid from dept;


Instance

SQL> select * from Employee
2/

ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION
-----------------------------------------------------------------------------
01 Jason Martin 25-JUL-96 25-JUL-06 1234.56 Toronto Programmer
02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78 Vancouver Tester
03 James Smith 12-DEC-78 15-MAR-90 6544.78 Vancouver Tester
04 Celia Rice 24-OCT-82 21-APR-99 2344.78 Vancouver Manager
05 Robert Black 15-JAN-84 08-AUG-98 2334.78 Vancouver Tester
06 Linda Green 30-JUL-87 04-JAN-96 4322.78 New York Tester
07 David Larry 31-DEC-90 12-FEB-98 7897.78 New York Manager
08 James Cat 17-SEP-96 15-apr-01232.78 Vancouver Tester

8 rows selected.

SQL>
SQL>
SQL> SELECT ROWID, id FROM employee
2/

ROWID
----------------------
AAAFx7AABAAAKjCAAA 01
AAAFx7AABAAAKjCAAB 02
AAAFx7AABAAAKjCAAC 03
AAAFx7AABAAAKjCAAD 04
AAAFx7AABAAAKjCAAE 05
AAAFx7AABAAAKjCAAF 06
AAAFx7AABAAAKjCAAG 07
AAAFx7AABAAAKjCAAH 08

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.