Table of Contents
1. Overview of saving information in rowid
2. Verify and view the rowid content
Home Database Oracle Detailed explanation of rowid in Oracle Study Guide

Detailed explanation of rowid in Oracle Study Guide

Mar 15, 2022 pm 06:03 PM
oracle

This article brings you relevant knowledge about Oracle, which mainly introduces related issues about rowid. Each row of data in the Oracle database table has a unique identifier. Or called rowid, it is usually used inside Oracle to access data. I hope it will be helpful to everyone.

Detailed explanation of rowid in Oracle Study Guide

Recommended tutorial: "Oracle Learning Tutorial"

1. Overview of saving information in rowid

oracle database Each row of data in the table has a unique identifier, or rowid, which is usually used to access data within Oracle. rowid requires 10 bytes of storage space and uses 18 characters to display. This value indicates the specific physical location of the row in the Oracle database. Rowid can be used in a query to indicate that the value is included in the query results.

Save rowid requires 10 bytes or 80 binary bits. An extended rowid is stored in 10 bytes, with a total of 80 bits, including obj#32bit, rfile#10bit, block#22bit, and row#16bit. Therefore, the relative file number cannot exceed 1023, that is, the number of data files in a table space cannot exceed 1023 (there is no file with file number 0). A datafile can only have 2^22=4M blocks, and no more than 1023 blocks can be included in one block. 2^16=64K rows of data. There cannot be more than 2^32=4G objects in a database.
These 80 binary bits are:
1. Data object number, indicating the number of the database object to which this row belongs. Each data object is uniquely assigned a number when the database is created, and this number is unique . The data object number occupies approximately 32 bits.
2. Corresponding file number, indicating the number of the file where the row is located. Each file label in the table space is unique. The file number occupies 10 digits.
3. Block number, indicating the location of the block of the file where the line is redirected. The block number requires 22 digits.
4. Row number, indicating the specific position of the row in the row directory. The row number requires 16 digits.
This adds up to 80 bits.

Note: Before Oracle 8 version, rowid was composed of file# block# row#, occupying 6 bytes of space, 10 bit file#, 22bit block#, 16 bit row# . Oracle8 and later versions change the space to 10 bytes.

Oracle's physical extended ROWID has 18 bits, each bit is encoded in 64 bits, using A~Z, a~z, 0~9, ,/ A total of 64 characters are represented. A represents 0, B represents 1, ...Z represents 25, a represents 26, ...z represents 51, 0 represents 52, ..., 9 represents 61, represents 62, / represents 63.

SELECT T.ROWID, T.* FROM DEPT T
Copy after login

In order to verify that the storage space of rowid is 10 bytes, including 32bit object#, 10bit rfile#, 22bit block#, and 16bit row#. We need to use the dump function.

select rowid,dump(rowid,16) from DEPT
Copy after login

2. Verify and view the rowid content

1. Use the function in the dbms_rowid package to view

SELECT ROWID,
       DBMS_ROWID.ROWID_OBJECT(ROWID) AS OBJECT,
       DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) AS FILENUM,
       DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) AS BLOCK,
       DBMS_ROWID.ROWID_ROW_NUMBER(ROWID) AS ROWN
  FROM DEPT;
Copy after login

The results are as follows:

2. Query data information from the table

1) Query object number: DATA_OBJECT_ID

SELECT OBJECT_NAME, OBJECT_TYPE, SUBOBJECT_NAME, OBJECT_ID, DATA_OBJECT_ID
  FROM DBA_OBJECTS T
 WHERE T.OBJECT_NAME ='DEPT'
 AND T.OWNER = 'CHF';
Copy after login

The results are as follows:

Description: The difference between DATA_OBJECT_ID and OBJECT_ID

Object_id and data_object_id are both unique identifiers of objects.

object_id is the logical identification of the object

data_object_id is the physical identification of the object

Only tables, indexes, and undo objects with actual physical storage locations have data_object_id. For objects without physical storage, data_object_id is empty. For example: (procedure, function, package, data type, db link, mv definition, view definition, temporary table, partition table definition, etc.)

In most cases, the two are equal. However, after truncate, move, rebuild and other operations are performed on the object, the data_object_id will change, but the object_id will not change.

Perform the truncate operation on the target DEPT, code: TRUNCATE TABLE DEPT;

Query the results again:

Replace the truncate operation Re-insert the data into the table and check that the rowid representing the object number has changed from AAAUOO to AAAUOP, increasing by 1.

2) Query file number:

SELECT T.SEGMENT_NAME, T.HEADER_BLOCK, T.BLOCKS, T.EXTENTS, T.RELATIVE_FNO
  FROM DBA_SEGMENTS T
 WHERE T.SEGMENT_NAME = 'DEPT'
   AND T.OWNER = 'CHF';
Copy after login

HEADER_BLOCK: The first data block number of this table

BLOCKS: The number of the first data block of this table Number of data blocks

RELATIVE_FNO: Relative file number

The results are as follows:

说明:

从Oracle8开始,Oracle开始使用“相对文件号”,使原来一个数据库最多只能有1023个文件,扩展为一个表空间最多可以有1023个文件,每个库最多可以有65534个文件

验证文件号

SELECT T.TABLE_NAME,
       T.TABLESPACE_NAME,
       G.FILE_NAME,
       G.FILE_ID,
       G.RELATIVE_FNO
  FROM DBA_TABLES T
 INNER JOIN DBA_DATA_FILES G
    ON G.TABLESPACE_NAME = T.TABLESPACE_NAME
 WHERE T.TABLE_NAME = 'DEPT'
 AND T.OWNER = 'CHF';
Copy after login

执行结果:

因为创建用户时没用指定默认表空间,建表时也没用指定表空间,所以此处使用的USERS表空间(大家不必在意这些细节...),可以看到文件号和相对文件号都是 4 ,这是因为我的数据库中每个表空间只有一个数据文件,如果一个表空间有多个数据文件,这两个值有可能不一样。

知识扩展:

我们可以使用跟踪文件查看数据文件信息,命令:alter session set events 'immediate trace name FILE_HDRS level 10';

执行完此代码后,将在数据库服务器生成一个跟踪文件,查看文件路径代码:

select
  u_dump.value || '/' ||
  db_name.value || '_ora_' ||
  v$process.spid ||
  nvl2(v$process.traceid, '_' || v$process.traceid, null )
  || '.trc' "Trace File"
from
v$parameter u_dump
cross join v$parameter db_name
cross join v$process
join v$session
on v$process.addr = v$session.paddr
where
  u_dump.name = 'user_dump_dest' and
  db_name.name = 'db_name' and
  v$session.audsid=sys_context('userenv','sessionid');
Copy after login

推荐教程:《Oracle教程

The above is the detailed content of Detailed explanation of rowid in Oracle Study Guide. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Function to calculate the number of days between two dates in oracle Function to calculate the number of days between two dates in oracle May 08, 2024 pm 07:45 PM

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The order of the oracle database startup steps is The order of the oracle database startup steps is May 10, 2024 am 01:48 AM

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

How to use interval in oracle How to use interval in oracle May 08, 2024 pm 07:54 PM

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

How to see the number of occurrences of a certain character in Oracle How to see the number of occurrences of a certain character in Oracle May 09, 2024 pm 09:33 PM

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

How to replace string in oracle How to replace string in oracle May 08, 2024 pm 07:24 PM

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

See all articles