如何在具有不同数据类型的复合键上添加集群?
How do i add a cluster on a composite key with different datatypes?
我有几个 table 想要聚类,但是,我已将问题归结为这个 table。这就是我创建集群的方式:
create cluster xyz_clus
(xyz_key int,
date1 date,
time timestamp
);
这是我添加索引的方式:
create index xyz_clus_idx on cluster xyz_clus;
这是我制作的table:
create table ABC
(
PRIMARY KEY (date1, time, number1),
date1 date,
time timestamp(0),
number1 int not null,
classnumber varchar(7) not null,
constraint timeslot_classnumber_fk Foreign Key (classnumber) references class (classnumber)
)
cluster xyz_clus(date1, time, number1);
但是,无论我多么努力,我都会不断收到此错误
ORA-01753: column definition incompatible with clustered column definition
正如我在您的 中所解释的,数据类型 a 需要完全匹配。以下代码有效:
CREATE TABLE abc (
date1 DATE,
time TIMESTAMP,
number1 INT NOT NULL,
classnumber VARCHAR2(7) NOT NULL,
PRIMARY KEY (date1, time, number1),
CONSTRAINT timeslot_classnumber_fk FOREIGN KEY (classnumber)
REFERENCES CLASS (classnumber)
) CLUSTER xyz_clus(number1, date1, time);
Table ABC created
但是,这会导致错误,因为它在 table 中使用了 TIMESTAMP(0)
,在集群中使用了 TIMESTAMP
:
CREATE TABLE abc (
date1 DATE,
time TIMESTAMP(0),
number1 INT NOT NULL,
classnumber VARCHAR2(7) NOT NULL,
PRIMARY KEY (date1, time, number1),
CONSTRAINT timeslot_classnumber_fk FOREIGN KEY (classnumber)
REFERENCES CLASS (classnumber)
) CLUSTER xyz_clus(number1, date1, time);
ORA-01753: column definition incompatible with clustered column definition
同样,复合键中列的顺序也很重要。以下查询具有正确的 TIMESTAMP
,但 table 中列的顺序是 DATE, TIMESTAMP, INT
,而在集群 INT, DATE, TIMESTAMP
中:
CREATE TABLE abc (
date1 DATE,
time TIMESTAMP,
number1 INT NOT NULL,
classnumber VARCHAR2(7) NOT NULL,
PRIMARY KEY (date1, time, number1),
CONSTRAINT timeslot_classnumber_fk FOREIGN KEY (classnumber)
REFERENCES CLASS (classnumber)
) CLUSTER xyz_clus(date1, time, number1);
ORA-01753: column definition incompatible with clustered column definition
我有几个 table 想要聚类,但是,我已将问题归结为这个 table。这就是我创建集群的方式:
create cluster xyz_clus
(xyz_key int,
date1 date,
time timestamp
);
这是我添加索引的方式:
create index xyz_clus_idx on cluster xyz_clus;
这是我制作的table:
create table ABC
(
PRIMARY KEY (date1, time, number1),
date1 date,
time timestamp(0),
number1 int not null,
classnumber varchar(7) not null,
constraint timeslot_classnumber_fk Foreign Key (classnumber) references class (classnumber)
)
cluster xyz_clus(date1, time, number1);
但是,无论我多么努力,我都会不断收到此错误
ORA-01753: column definition incompatible with clustered column definition
正如我在您的
CREATE TABLE abc (
date1 DATE,
time TIMESTAMP,
number1 INT NOT NULL,
classnumber VARCHAR2(7) NOT NULL,
PRIMARY KEY (date1, time, number1),
CONSTRAINT timeslot_classnumber_fk FOREIGN KEY (classnumber)
REFERENCES CLASS (classnumber)
) CLUSTER xyz_clus(number1, date1, time);
Table ABC created
但是,这会导致错误,因为它在 table 中使用了 TIMESTAMP(0)
,在集群中使用了 TIMESTAMP
:
CREATE TABLE abc (
date1 DATE,
time TIMESTAMP(0),
number1 INT NOT NULL,
classnumber VARCHAR2(7) NOT NULL,
PRIMARY KEY (date1, time, number1),
CONSTRAINT timeslot_classnumber_fk FOREIGN KEY (classnumber)
REFERENCES CLASS (classnumber)
) CLUSTER xyz_clus(number1, date1, time);
ORA-01753: column definition incompatible with clustered column definition
同样,复合键中列的顺序也很重要。以下查询具有正确的 TIMESTAMP
,但 table 中列的顺序是 DATE, TIMESTAMP, INT
,而在集群 INT, DATE, TIMESTAMP
中:
CREATE TABLE abc (
date1 DATE,
time TIMESTAMP,
number1 INT NOT NULL,
classnumber VARCHAR2(7) NOT NULL,
PRIMARY KEY (date1, time, number1),
CONSTRAINT timeslot_classnumber_fk FOREIGN KEY (classnumber)
REFERENCES CLASS (classnumber)
) CLUSTER xyz_clus(date1, time, number1);
ORA-01753: column definition incompatible with clustered column definition