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 2022-02-24 09:57  JennyYu  阅读(1092)  评论(0编辑  收藏  举报