程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> 探究oracleclob字段是如何存儲的

探究oracleclob字段是如何存儲的

編輯:Oracle教程

clob字段存儲的是文本,如果存儲少於4000個字節則clob字段會和記錄存放在一起,如果存儲超過4000個字節,則不會與記錄存放在一起。值得注意的是,這裡的4000個字節並不是等同於varchar2(4000),那相當於什麼呢,請看下列實驗,數據庫版本是10.2.0.1.0:

drop table test_clob purge;
create table test_clob
(
id number,
clob1 clob
);

insert into test_clob values(1,Lpad('111',100,'1'));--236
insert into test_clob values(2,Lpad('222',500,'1'));--1036
insert into test_clob values(3,Lpad('333',1000,'1'));--2036
insert into test_clob values(4,Lpad('444',1982,'1'));--4000
insert into test_clob values(5,Lpad('555',1983,'1'));--4002
commit;

select rowid,
dbms_rowid.rowid_object(rowid) object_id,
dbms_rowid.rowid_relative_fno(rowid) file_id,
dbms_rowid.rowid_block_number(rowid) block_id,
dbms_rowid.rowid_row_number(rowid) num
from test_clob;
ROWID OBJECT_ID FILE_ID BLOCK_ID NUM
------------------ ---------- ---------- ---------- ----------
AAAYQbAAFAADRpcAAA 99355 5 858716 0
AAAYQbAAFAADRpcAAB 99355 5 858716 1
AAAYQbAAFAADRpcAAC 99355 5 858716 2
AAAYQbAAFAADRpdAAA 99355 5 858717 0
AAAYQbAAFAADRpgAAA 99355 5 858720 0


alter system dump datafile 5 block 858716;
alter system dump datafile 5 block 858717;
alter system dump datafile 5 block 858720;

查看dump文件可以看到:

col 0: [ 2] c1 02 --記錄id=1 為啥是1 請看我以前的帖子:http://blog.csdn.net/stevendbaguo/article/details/8010105
col 1: [236]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 02 1a 85 00 d8 09 00 00
00 00 00 00 c8 00 00 00 00 00 01 00 31 00 31 00 31 00 31 00 31 00 31 00 31
...........................................................................
...........................................................................

col 0: [ 2] c1 03 --記錄id=2
col 1: [1036]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 02 1a 86 03 f8 09 00 00
00 00 00 03 e8 00 00 00 00 00 01 00 31 00 31 00 31 00 31 00 31 00 31 00 31
...........................................................................
...........................................................................


col 0: [ 2] c1 04 --記錄id=3
col 1: [2036]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 02 1a 87 07 e0 09 00 00
00 00 00 07 d0 00 00 00 00 00 01 00 31 00 31 00 31 00 31 00 31 00 31 00 31
...........................................................................
...........................................................................

col 0: [ 2] c1 05 --記錄id=4
col 1: [4000]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 02 1a 88 0f 8c 09 00 00
00 00 00 0f 7c 00 00 00 00 00 01 00 31 00 31 00 31 00 31 00 31 00 31 00 31
...........................................................................
...........................................................................


col 0: [ 2] c1 06 --記錄id=5
col 1: [40]
00 54 00 01 02 0c 80 00 00 02 00 00 00 01 00 00 00 02 1a 89 00 14 05 00 00
00 00 00 0f 7e 00 00 00 00 00 02 01 4d 98 ac

記錄 Lpad('111',100,'1'));--236
記錄 Lpad('222',500,'1')--1036
記錄 Lpad('333',1000,'1')--2036
記錄 Lpad('444',1982,'1')--4000
記錄 Lpad('555',1983,'1')--4002

看出規律來了,第一條記錄我們認為的長度是100,存在block中的長度是236,就是236=100*2+36,其他的規律都是這樣。同時也可以看到存儲超過4000個字節,就是長度為1982時這個就是臨界值,大於這個之後就clob就存到其他地方了。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved