Oracle 19c SQL

  1. Home
  2. Docs
  3. Oracle 19c SQL
  4. 7 Pseudo Columns
  5. 7.3 ROWID

7.3 ROWID

The ROWID pseudo column returns the address for each row in a table. ROWID values are stored in database and uniquely identifies rows in a table. ROWIDs are the fastest way to access a single row.

If you delete and reinsert a row, then its ROWID may change. Because of this reason, you should not use ROWID as the primary key of a table.

SELECT ROWID, Deptno, Dname, Loc 
  FROM Dept;

ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAJu6AAAAAAAPmAAA         10 ACCOUNTING     NEW YORK
AAAJu6AAAAAAAPmAAB         20 RESEARCH       DALLAS
AAAJu6AAAAAAAPmAAC         30 SALES          CHICAGO
AAAJu6AAAAAAAPmAAD         40 OPERATIONS     BOSTON
/*
    Accessing rows using ROWID in WHERE clause
*/

SELECT ROWID, Deptno, Dname, Loc 
  FROM Dept
 WHERE ROWID = 'AAAJu6AAAAAAAPmAAB';

ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAJu6AAAAAAAPmAAB         20 RESEARCH       DALLAS


SELECT ROWID, Deptno, Dname, Loc 
  FROM Dept
 WHERE ROWID IN('AAAJu6AAAAAAAPmAAB', 'AAAJu6AAAAAAAPmAAA');

ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAJu6AAAAAAAPmAAA         10 ACCOUNTING     NEW YORK
AAAJu6AAAAAAAPmAAB         20 RESEARCH       DALLAS
/*
    Verify ROWID changes when a row is deleted and inserted again
*/

DELETE FROM Dept
WHERE ROWID = 'AAAJu6AAAAAAAPmAAD';

1 row deleted.


SELECT ROWID, Deptno, Dname, Loc 
  FROM Dept;

ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAJu6AAAAAAAPmAAA         10 ACCOUNTING     NEW YORK
AAAJu6AAAAAAAPmAAB         20 RESEARCH       DALLAS
AAAJu6AAAAAAAPmAAC         30 SALES          CHICAGO


INSERT INTO Dept
VALUES(40, 'OPERATIONS', 'BOSTON');

1 row created.


SELECT ROWID, Deptno, Dname, Loc 
  FROM Dept;

ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAAJu6AAAAAAAPmAAA         10 ACCOUNTING     NEW YORK
AAAJu6AAAAAAAPmAAB         20 RESEARCH       DALLAS
AAAJu6AAAAAAAPmAAC         30 SALES          CHICAGO
AAAJu6AAAAAAAPmAAD         40 OPERATIONS     BOSTON

Although you can use the ROWID pseudo column in the SELECT and WHERE clause of a query, these pseudo column values are not actually stored in the database. Hence, you can not insert, update, or delete a value of the ROWID pseudo column.

/*
    Update ROWID pseudo column value is not allowed.
*/

UPDATE Dept
   SET ROWID = 'AAAJu6AAAAAAAPlAAA'
 WHERE Deptno = 40;

ERROR at line 2:
ORA-01747: invalid user.table.column, table.column, or column specification
Was this article helpful to you? Yes No

How can we help?