search
HomeDatabaseOracleDetailed explanation of rowid in Oracle Study Guide

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

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

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;

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';

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';

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';

执行结果:

因为创建用户时没用指定默认表空间,建表时也没用指定表空间,所以此处使用的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');

推荐教程:《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
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
什么是oracle asm什么是oracle asmApr 18, 2022 pm 04:16 PM

oracle asm指的是“自动存储管理”,是一种卷管理器,可自动管理磁盘组并提供有效的数据冗余功能;它是做为单独的Oracle实例实施和部署。asm的优势:1、配置简单、可最大化推动数据库合并的存储资源利用;2、支持BIGFILE文件等。

oracle怎么查询所有索引oracle怎么查询所有索引May 13, 2022 pm 05:23 PM

方法:1、利用“select*from user_indexes where table_name=表名”语句查询表中索引;2、利用“select*from all_indexes where table_name=表名”语句查询所有索引。

oracle全角怎么转半角oracle全角怎么转半角May 13, 2022 pm 03:21 PM

在oracle中,可以利用“TO_SINGLE_BYTE(String)”将全角转换为半角;“TO_SINGLE_BYTE”函数可以将参数中所有多字节字符都替换为等价的单字节字符,只有当数据库字符集同时包含多字节和单字节字符的时候有效。

Oracle怎么查询端口号Oracle怎么查询端口号May 13, 2022 am 10:10 AM

在Oracle中,可利用lsnrctl命令查询端口号,该命令是Oracle的监听命令;在启动、关闭或重启oracle监听器之前可使用该命令检查oracle监听器的状态,语法为“lsnrctl status”,结果PORT后的内容就是端口号。

oracle怎么删除sequenceoracle怎么删除sequenceMay 13, 2022 pm 03:35 PM

在oracle中,可以利用“drop sequence sequence名”来删除sequence;sequence是自动增加数字序列的意思,也就是序列号,序列号自动增加不能重置,因此需要利用drop sequence语句来删除序列。

oracle怎么查询数据类型oracle怎么查询数据类型May 13, 2022 pm 04:19 PM

在oracle中,可以利用“select ... From all_tab_columns where table_name=upper('表名') AND owner=upper('数据库登录用户名');”语句查询数据库表的数据类型。

oracle查询怎么不区分大小写oracle查询怎么不区分大小写May 10, 2022 pm 05:45 PM

方法:1、利用“LOWER(字段值)”将字段转为小写,或者利用“UPPER(字段值)”将字段转为大写;2、利用“REGEXP_LIKE(字符串,正则表达式,'i')”,当参数设置为“i”时,说明进行匹配不区分大小写。

Oracle怎么修改sessionOracle怎么修改sessionMay 13, 2022 pm 05:06 PM

方法:1、利用“alter system set sessions=修改后的数值 scope=spfile”语句修改session参数;2、修改参数之后利用“shutdown immediate – startup”语句重启服务器即可生效。

See all articles

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function