os: centos 7.4
db: oracle 11.2.0.4
版本
# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
# su - oracle
$ sqlplus / as sysdba;
SQL*Plus: Release 11.2.0.4.0 Production on Wed Dec 18 18:19:10 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
创建表
create table tmp_t0(
c0 integer,
c1 clob,
c2 clob,
c3 clob
)
;
insert into tmp_t0(c0,c1,c2,c3)
values(1,'a','a','a')
;
commit;
查看大小
select us.segment_name,
us.segment_type,
us.BYTES,
us.blocks
from user_segments us
where 1=1
and us.segment_name in ( select 'TMP_T0'
from dual
union all
select ul.SEGMENT_NAME
from user_lobs ul
where 1=1
and ul.TABLE_NAME='TMP_T0'
union all
select ul.INDEX_NAME
from user_lobs ul
where 1=1
and ul.TABLE_NAME='TMP_T0'
)
;
插入 20W 数据
begin
for c_f in (
select level as id
from dual
connect by level <= 200000
)
loop
insert into tmp_t0(c0,c1,c2,c3)
values(
c_f.id,
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'
);
end loop;
commit;
end;
查看大小
select us.segment_name,
us.segment_type,
us.BYTES,
us.blocks
from user_segments us
where 1=1
and us.segment_name in ( select 'TMP_T0'
from dual
union all
select ul.SEGMENT_NAME
from user_lobs ul
where 1=1
and ul.TABLE_NAME='TMP_T0'
union all
select ul.INDEX_NAME
from user_lobs ul
where 1=1
and ul.TABLE_NAME='TMP_T0'
)
;
发现 LOB 对象大小没有变化。
再插入 2W 条长字符串数据
declare
v_lob varchar2(30000):=' ';
begin
for c_e in (
select level as id
from dual
connect by level <= 100
)
loop
v_lob:= 'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'||v_lob;
end loop;
for c_f in (
select level as id
from dual
connect by level <= 20000
)
loop
insert into tmp_t0(c0,c1,c2,c3)
values(
c_f.id,
v_lob,
v_lob,
v_lob)
;
end loop;
commit;
end;
再查看大小
select us.segment_name,
us.segment_type,
us.BYTES,
us.blocks
from user_segments us
where 1=1
and us.segment_name in ( select 'TMP_T0'
from dual
union all
select ul.SEGMENT_NAME
from user_lobs ul
where 1=1
and ul.TABLE_NAME='TMP_T0'
union all
select ul.INDEX_NAME
from user_lobs ul
where 1=1
and ul.TABLE_NAME='TMP_T0'
)
;
lob 字段的大小有明显增长。
说明往 clob 字段插入数值时,当长度大于某个值时,才会存储的独立的 LOB 对象中。小于某个值时,就会当成 varchar 类型使用。
这个临界值是多少呢?
扫描二维码关注公众号,回复:
8813366 查看本文章
经过查找资料并验证后发现当存储超过4000个字节,就是长度为1982 就是临界值。
大于 1982 ,就会存储到独立的LOB对象中。
小于等于1982,存储在原表中。
参考: