请教创建索引遇到ora-01450的错误

rigye 2006-03-06 08:37:00
创建一个表:
create table test3(a varchar2(4000), b varchar2(4000));
然后在表上创建一个索引
create index ix_test3_ab on test3(a,b);
系统报错:
ora-01450,maxinum key length(6898) exceed
其中系统的db_block_size为8k
请问6398这个数字是怎么计算出来的?
谢谢!
...全文
555 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
boydgmx 2006-03-07
  • 打赏
  • 举报
回复
上google搜索 "ORA-01450"

看第一篇的快照,原文打不开,快照格式比较乱,打开自己整理一下。

英文的。

说得很明白,不过最终的数据与实际情况有些出入。

我觉得数据不是最重要的,重要的在于理解了为什么。

正如这个错误在文档中的说明:与当前环境的设置有关。

我的理解,这里的环境设置包括:
DB_BLOCK_SIZE
index 的 PCT_FREE、INITRANS
等等参数。

也就是说,这个值对于不同的平台、不同的用户设置,会不同。
rigye 2006-03-06
  • 打赏
  • 举报
回复
其实我想问这个问题的根本目的在于6398这个值是怎么来的。由此可以加深对ORACLE数据储存方面的理解,有哪位老兄了解的?请教!
cenlmmx 2006-03-06
  • 打赏
  • 举报
回复
ORA-01450 maximum key length exceeded

Cause The combined length of all the columns specified in a CREATE INDEX statement exceeded the maximum index length. The maximum index length varies by operating system. The total index length is computed as the sum of the width of all indexed columns plus the number of indexed columns. Date fields have a length of 7, character fields have their defined length, and numeric fields have a length of 22. Numeric length = (precision/2) + 1. If negative, add +1.
Action Select columns to be indexed so the total index length does not exceed the maximum index length for the operating system. See also your operating system-specific Oracle documentation.

Copyright (C) 1998, Oracle Corporation
也就是说把索引列的长度太长了,改短点.
zhpsam109 2006-03-06
  • 打赏
  • 举报
回复
一目了然,佩服楼上的精神!
boydgmx 2006-03-06
  • 打赏
  • 举报
回复
楼上的,你肯定没有测试过。

不是索引名称的问题。

SQL> create table test3(a varchar2(4000), b varchar2(4000));

表已创建。

SQL> create index ix_test3_ab on test3(a,b);
create index ix_test3_ab on test3(a,b)
*
ERROR 位于第 1 行:
ORA-01450: 超出最大的关键字长度 (6398)

SQL> DROP TABLE TEST3 CASCADE CONSTRAINTS

表已丢弃。

SQL> create table test3(a varchar2(400), b varchar2(400));

表已创建。

SQL> create index ix_test3_ab on test3(a,b);

索引已创建。

看出来了吧?你的两个字段建立的复合索引,单个索引项最大可能是4000+4000共计8000个字节,有可能超过6398这个限制,因此索引无法创建。

如果你没有那么多内容要存储的话,就把字段定义小点。
goldarcher2005 2006-03-06
  • 打赏
  • 举报
回复
create index ix_test3_ab on test3(a,b);

ix_test3_ab 太长了,改短点

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧