随笔-49  评论-543  文章-0  trackbacks-0
Oracle® Database SQL Reference
10g Release 1 (10.1)

Part Number B10759-01

ROWID

For each row in the database, the ROWID pseudocolumn returns the address of the row. Oracle Database rowid values contain information necessary to locate a row:

  • The data object number of the object

  • The data block in the datafile in which the row resides

  • The position of the row in the data block (first row is 0)

  • The datafile in which the row resides (first file is 1). The file number is relative to the tablespace.

Usually, a rowid value uniquely identifies a row in the database. However, rows in different tables that are stored together in the same cluster can have the same rowid.

Values of the ROWID pseudocolumn have the datatype ROWID or UROWID. Please refer to "ROWID Datatype " and "UROWID Datatype " for more information.

Rowid values have several important uses:

  • They are the fastest way to access a single row.

  • They can show you how the rows in a table are stored.

  • They are unique identifiers for rows in a table.

You should not use ROWID as the primary key of a table. If you delete and reinsert a row with the Import and Export utilities, for example, then its rowid may change. If you delete a row, then Oracle may reassign its rowid to a new row inserted later.

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


Example

This statement selects the address of all rows that contain data for employees in department 20:

SELECT ROWID, last_name
FROM employees
WHERE department_id = 20;



ROWID Datatype

Each row in the database has an address. You can examine a row address by querying the pseudocolumn ROWID. Values of this pseudocolumn are strings representing the address of each row. These strings have the datatype ROWID. You can also create tables and clusters that contain actual columns having the ROWID datatype. Oracle Database does not guarantee that the values of such columns are valid rowids. Please refer to Chapter 3, " Pseudocolumns" for more information on the ROWID pseudocolumn.

Restricted Rowids

Beginning with Oracle8, Oracle SQL incorporated an extended format for rowids to efficiently support partitioned tables and indexes and tablespace-relative data block addresses (DBAs) without ambiguity.

Character values representing rowids in Oracle7 and earlier releases are called restricted rowids. Their format is as follows:

block.row.file

where:

  • block is a hexadecimal string identifying the data block of the datafile containing the row. The length of this string depends on your operating system.

  • row is a four-digit hexadecimal string identifying the row in the data block. The first row of the block has a digit of 0.

  • file is a hexadecimal string identifying the database file containing the row. The first datafile has the number 1. The length of this string depends on your operating system.

Extended Rowids

The extended ROWID datatype stored in a user column includes the data in the restricted rowid plus a data object number. The data object number is an identification number assigned to every database segment. You can retrieve the data object number from the data dictionary views USER_OBJECTS, DBA_OBJECTS, and ALL_OBJECTS. Objects that share the same segment (clustered tables in the same cluster, for example) have the same object number.

Extended rowids are stored as base 64 values that can contain the characters A-Z, a-z, 0-9, and the plus sign (+) and forward slash (/). Extended rowids are not available directly. You can use a supplied package, DBMS_ROWID, to interpret extended rowid contents. The package functions extract and provide information that would be available directly from a restricted rowid as well as information specific to extended rowids.


See Also:

PL/SQL Packages and Types Reference for information on the functions available with the DBMS_ROWID package and how to use them

posted on 2010-01-22 13:12 my god 阅读(236) 评论(0)  编辑  收藏 所属分类: 技术—数据库