SQL ORA-01408: 此类列列表已编入索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20497613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:24:18  来源:igfitidea点击:

ORA-01408: such column list already indexed

sqloracleoracle-sqldeveloper

提问by My-Name-Is

Oracle SQL-Developer generates DDL statements of already exising database tables (items). It's quite strange that the generated DDL statements can't be applied within a new database instance. Here's a simplified example of the DDL

Oracle SQL-Developer 生成现有数据库表(项)的 DDL 语句。很奇怪,生成的 DDL 语句不能应用于新的数据库实例。这是 DDL 的简化示例

CREATE TABLE AB
  (
    "A"      NUMBER(*,0),
    "B"   NUMBER(*,0),
    "C" VARCHAR2(255 BYTE),
    CONSTRAINT "CHK_AB_A_NN" CHECK (A       IS NOT NULL) ENABLE,
    CONSTRAINT "CHK_AB_B_NN" CHECK (B       IS NOT NULL) ENABLE,
    CONSTRAINT "PK_AB" PRIMARY KEY ("A", "B")
  );
CREATE INDEX "IDX_AB_A" ON "AB"("A");
CREATE INDEX "IDX_AB_B" ON "AB"("B");
CREATE UNIQUE INDEX "PK_AB" ON "AB"("A", "B");

If I execute those statements within a new oracle instance, I get the error:

如果我在新的 oracle 实例中执行这些语句,则会收到错误消息:

SQL-Fehler: ORA-01408: Diese Spaltenliste hat bereits einen Index 1. 00000 - "such column list already indexed"

SQL-Fehler: ORA-01408: Diese Spaltenliste hat bereits einen Index 1. 00000 - "such column list already indexed"

What's the reason for this error?

这个错误的原因是什么?

回答by Alen Oblak

The part:

那个部分:

CONSTRAINT "PK_AB" PRIMARY KEY ("A", "B")

is generating an index. Primary key constraint cannot exists without an index. However, the part:

正在生成索引。没有索引就不能存在主键约束。但是,该部分:

CREATE UNIQUE INDEX "PK_AB" ON "AB"("A", "B");

is generating yet another index with the same columns. This is the reason for the error. Quite strange though, that the Oracle tool is generating a wrong script :) Maybe it's a bug.

正在生成另一个具有相同列的索引。这就是错误的原因。不过很奇怪,Oracle 工具生成了错误的脚本 :) 也许这是一个错误。

回答by tvm

Your primary key constraint in the CREATE TABLE statement automatically creates unique index on ("A","B"), since it's PRIMARY KEY. Error is then raised, since you try to re-create already existing UNIQUE INDEX on same columns.

CREATE TABLE 语句中的主键约束会自动在 ("A","B") 上创建唯一索引,因为它是 PRIMARY KEY。然后引发错误,因为您尝试在相同的列上重新创建现有的 UNIQUE INDEX。

UPDATE: I've tested it with Oracle SQL Developer 3.2.20.09 and the above mentioned problem is not present. Are you possibly using older version ?

更新:我已经使用 Oracle SQL Developer 3.2.20.09 对其进行了测试,并且不存在上述问题。您可能使用旧版本吗?