随笔 - 116  文章 - 5  评论 - 1  阅读 - 14万

oracle 表中字段长度设置太长给在线创建索引或在线重新编译索引造成的问题

开发的同学建oracle 表时候,字段类型经常设置会设置成varchar2(4000), 因为varchar2是可变长度字符串,实际使用多少就占用多少,设置的长度,是说字段可达到的最大长度,但是在建索引的时候发现一个问题:

我们使用在线创建索引或在线重新编译索引时会报出字段长度超长的问题,虽然这列上实际字段最大长度只有几个字符。

下面的实验数据:

 

复制代码
SQL> create table aa(id number(10),name varchar2(4000));

   Table created.


SQL> create index idx_name on aa(name) online;

Index created.

SQL> insert into aa values(10,'afdsafsa');

1 row created.

SQL> commit;

Commit complete.

SQL> alter index idx_name rebuild;

Index altered.

SQL> alter index idx_name rebuild online;
alter index idx—me rebuild online
            *
ERROR at line 1:
ORA-00972: identifier is too long


SQL> drop index idx_name;

Index dropped.

SQL> create index idx_name on aa(name) online;
create index idx_name on aa(name) online
                         *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01450: maximum key length (3215) exceeded


SQL> create index idx_name on aa(name);

Index created.

SQL> alter index idx_name rebuild;

Index altered.
复制代码

可以看出,不使用online创建索引和rebuild索引是没有问题的,使用online时会报错,字段长度不能超过3215个字符。

 

posted on   JennyYu  阅读(1176)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示