Oracle嵌套表存储格式浅析
Oracle嵌套表很少用,下面来研究下其如何存储的。用一个例子,一个用户对应对个部门。
Oracle嵌套表很少用,下面来研究下其如何存储的。用一个例子,一个用户对应对个部门。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create type t_dept as object(
dept_id number,
dept_name varchar2(20)
)
/
SQL> create type t_dept_arry as varray(100) of t_dept
/
SQL> create table t_user(
user_id number,
user_name varchar2(10),
depts t_dept_arry
)
/
SQL> insert into t_user values(1,'张三',t_dept_arry(t_dept(100,'开发一组'),t_dept(200,'开发二组')));
SQL> insert into t_user values(2,'李四',t_dept_arry(t_dept(300,'设计一组'),t_dept(400,'设计二组')));
SQL> commit;
--要想遍历用户的所有部门信息,需要用table这种特殊的形式
SQL> select user_id,user_name,d.dept_id,d.dept_name from t_user u,table(u.depts) d;
USER_ID USER_NAME DEPT_ID DEPT_NAME
---------- ---------- ---------- --------------------
1 张三 100 开发一组
1 张三 200 开发二组
2 李四 300 设计一组
2 李四 400 设计二组
dump block看看:
block_row_dump:
tab 0, row 0, @0x3f47
tl: 81 fb: --H-FL-- lb: 0x1 cc: 3
col 0: [ 2] c1 02
col 1: [ 4] d5 c5 c8 fd
col 2: [69]
00 01 00 00 00 00 00 01 00 00 00 0a e4 23 00 37 09 00 00 00 00 00 00 27 00
00 00 00 00 01 88 01 27 01 01 00 02 0f 84 01 0f 02 c2 02 08 bf aa b7 a2 d2
bb d7 e9 0f 84 01 0f 02 c2 03 08 bf aa b7 a2 b6 fe d7 e9
tab 0, row 1, @0x3ef6
tl: 81 fb: --H-FL-- lb: 0x1 cc: 3
col 0: [ 2] c1 03
col 1: [ 4] c0 ee cb c4
col 2: [69]
00 01 00 00 00 00 00 01 00 00 00 0a e4 24 00 37 09 00 00 00 00 00 00 27 00
00 00 00 00 01 88 01 27 01 01 00 02 0f 84 01 0f 02 c2 04 08 c9 e8 bc c6 d2
bb d7 e9 0f 84 01 0f 02 c2 05 08 c9 e8 bc c6 b6 fe d7 e9
end_of_block_dump
insert into t_user values(3,'王五',t_dept_arry(t_dept(500,'家')));
commit;
block_row_dump:
tab 0, row 0, @0x3f5d
tl: 59 fb: --H-FL-- lb: 0x1 cc: 3
col 0: [ 2] c1 04
col 1: [ 4] cd f5 ce e5
col 2: [47]
00 01 00 00 00 00 00 01 00 00 00 0a e4 49 00 21 09 00 00 00 00 00 00 11 00
00 00 00 00 01 88 01 11 01 01 00 01 09 84 01 09 02 c2 06 02 bc d2
end_of_block_dump
--看了上面dump的结果,一头雾水,不知道是怎么存的,不过在user_objects中找到线索,有个lob字段
SQL> select object_name,object_type from user_objects s;
OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
SYS_LOB0000082685C00003$$ LOB
T_USER TABLE
T_DEPT_ARRY TYPE
T_DEPT TYPE
SQL> select column_name, segment_name, index_name
from user_lobs s
where s.table_name = 'T_USER';
COLUMN_NAM SEGMENT_NAME INDEX_NAME
---------- ------------------------------ ------------------------------
DEPTS SYS_LOB0000082685C00003$$ SYS_IL0000082685C00003$$
--再测试下跟普通的clob有什么区别
drop table test purge;
create table test
(
id number,
t_clob clob
);
insert into test values(1,'开发一组开发二组');
insert into test values(1,'设计一组设计二组');
insert into test values(1,'家');
commit;
tab 0, row 0, @0x3f5d
tl: 59 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 2] c1 02
col 1: [52]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 0a e4 4a 00 20 09 00 00
00 00 00 00 10 00 00 00 00 00 01 5f 00 53 d1 4e 00 7e c4 5f 00 53 d1 4e 8c
7e c4
LOB
Locator:
Length: 84(52)
Version: 1
Byte Length: 2
LobID: 00.00.00.01.00.00.00.0a.e4.4a
Flags[ 0x02 0x0c 0x80 0x00 ]:
Type: CLOB
Storage: BasicFile
Enable Storage in Row
Characterset Format: IMPLICIT
Partitioned Table: No
Options: VaringWidthReadWrite
Inode:
Size: 32
Flag: 0x09 [ Valid DataInRow ]
Future: 0x00 (should be '0x00')
Blocks: 0
Bytes: 16
Version: 00000.0000000001
Inline data[16]
Dump of memory from 0x00002AE680C155EC to 0x00002AE680C155FC
2AE680C155E0 D153005F [_.S.]
2AE680C155F0 C47E004E D153005F C47E8C4E [N.~._.S.N.~.]
tab 0, row 1, @0x3f22
tl: 59 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 2] c1 02
col 1: [52]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 0a e4 4b 00 20 09 00 00
00 00 00 00 10 00 00 00 00 00 01 8b be 8b a1 4e 00 7e c4 8b be 8b a1 4e 8c
7e c4
LOB
Locator:
Length: 84(52)
Version: 1
Byte Length: 2
LobID: 00.00.00.01.00.00.00.0a.e4.4b
Flags[ 0x02 0x0c 0x80 0x00 ]:
Type: CLOB
Storage: BasicFile
Enable Storage in Row
Characterset Format: IMPLICIT
Partitioned Table: No
Options: VaringWidthReadWrite
Inode:
Size: 32
Flag: 0x09 [ Valid DataInRow ]
Future: 0x00 (should be '0x00')
Blocks: 0
Bytes: 16
Version: 00000.0000000001
Inline data[16]
Dump of memory from 0x00002AE680C155B1 to 0x00002AE680C155C1
2AE680C155B0 8BBE8B01 7E004EA1 8BBE8BC4 7E8C4EA1 [.....N.~.....N.~]
2AE680C155C0 02012CC4 [.,..]
tab 0, row 2, @0x3ef5
tl: 45 fb: --H-FL-- lb: 0x1 cc: 2
col 0: [ 2] c1 02
col 1: [38]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 0a e4 4c 00 12 09 00 00
00 00 00 00 02 00 00 00 00 00 01 5b b6
LOB
Locator:
Length: 84(38)
Version: 1
Byte Length: 2
LobID: 00.00.00.01.00.00.00.0a.e4.4c
Flags[ 0x02 0x0c 0x80 0x00 ]:
Type: CLOB
Storage: BasicFile
Enable Storage in Row
Characterset Format: IMPLICIT
Partitioned Table: No
Options: VaringWidthReadWrite
Inode:
Size: 18
Flag: 0x09 [ Valid DataInRow ]
Future: 0x00 (should be '0x00')
Blocks: 0
Bytes: 2
Version: 00000.0000000001
Inline data[2]
选取两次的dump的内容,,不过还是不能确定两者是否等价:
00 01 00 00 00 00 00 01 00 00 00 0a e4 49 00 21 09 00 00 00 00 00 00 11 00
00 00 00 00 01 88 01 11 01 01 00 01 09 84 01 09 02 c2 06 02 bc d2
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 0a e4 4c 00 12 09 00 00
00 00 00 00 02 00 00 00 00 00 01 5b b6
总结:嵌套是通过lob在存储嵌套的内容的,TOM说作为一种存储机制,他更倾向于创建父子表,可以再创建一个视图,看上去像一个真正的嵌套表一样,嵌套表适合于编程构造。
在CentOS 6.4下安装Oracle 11gR2(x64)
Oracle 11gR2 在VMWare虚拟机中安装步骤
Debian 下 安装 Oracle 11g XE R2
本文永久更新链接地址:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.
