重庆思庄Oracle、Redhat认证学习论坛

标题: 创建引用分区报:ORA-14652: 不支持引用分区外键 [打印本页]

作者: 郑全    时间: 2023-8-30 18:51
标题: 创建引用分区报:ORA-14652: 不支持引用分区外键
CREATE TABLE new_order_items
( ORDER_ID NUMBER(12) ,
  LINE_ITEM_ID NUMBER(3) NOT NULL,
  PRODUCT_ID NUMBER NOT NULL,
  QUANTITY NUMBER NOT NULL,
  SALES_AMOUNT NUMBER NOT NULL,
  CONSTRAINT order_items_fk FOREIGN KEY(order_id) REFERENCES new_orders(order_id)
)
  PARTITION BY REFERENCE(order_items_fk);

ORA-14652: 不支持引用分区外键


[oracle@host01 ~]$ oerr ora 14652
14652, 00000, "reference partitioning foreign key is not supported"
// *Cause:  The specified partitioning foreign key was not supported
//          for reference-partitioned tables. All columns of the
//          partitioning foreign key must be constrained NOT NULL with
//          enabled, validated, and not deferrable constraints. Furthermore,
//          a virtual column cannot be part of the partitioning foreign key.
//* Action: Correct the statement to specify a supported

//          partitioning foreign key.

说明中提示了错误原因,如果使用Reference Partition,外键列是不允许为空的。标准外键定义并没有规定外键列必须为空,但是如果使用引用分区技术,就必须要求外键列不能为空。

这种约束其实也好理解。Reference Partition不需要明确指定分区键,但是实际上还是需分区键(或者称为分区因素)。如果没有外键值,也就失去了到主表分区的定位功能,Oracle必然不会允许创建。修改建表语句如下:

CREATE TABLE new_order_items
( ORDER_ID NUMBER(12)  not null,
  LINE_ITEM_ID NUMBER(3) NOT NULL
  PRODUCT_ID NUMBER NOT NULL,
  QUANTITY NUMBER NOT NULL,
  SALES_AMOUNT NUMBER NOT NULL,
  CONSTRAINT order_items_fk FOREIGN KEY(order_id) REFERENCES new_orders(order_id)
)

  PARTITION BY REFERENCE(order_items_fk);

即可。








欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2