我必须处理如下表(简化版):
CREATE TABLE "CE2"."TABLE1" (
"ID" NUMBER(38,0) NOT NULL ENABLE,
"SOME_IMPORTANT_COLUMN" NUMBER(38,0) NOT NULL ENABLE,
"NAME" VARCHAR2(80 BYTE) NOT NULL ENABLE,
"TABLE1_1_FK" NUMBER(38,0),
"TABLE1_2_FK" NUMBER(38,0),
CONSTRAINT "PK_TABLE1" PRIMARY KEY ("ID", "SOME_IMPORTANT_COLUMN") ENABLE,
CONSTRAINT "FK_TABLE1_1" FOREIGN KEY ("TABLE1_1_FK", "SOME_IMPORTANT_COLUMN") REFERENCES "CE2"."TABLE1" ("ID", "SOME_IMPORTANT_COLUMN") ENABLE,
CONSTRAINT "FK_TABLE1_2" FOREIGN KEY ("TABLE1_2_FK", "SOME_IMPORTANT_COLUMN") REFERENCES "CE2"."TABLE1" ("ID", "SOME_IMPORTANT_COLUMN") ENABLE
)
此表具有复合主键和两个自引用字段。另请注意,没有CASCADE DELETE行为。 我想在给定一组主键的情况下从该表中删除一些记录。 还必须删除引用目标记录(要删除的目标记录)的子记录。
如果我只有一个自引用字段,例如TABLE1_1_FK,我会写这个:
delete from table1 where (id, some_important_column) in (
select id, some_important_column from table1
start with (id, some_important_column) in ((1, 'b'), (2, 'd'))
connect by TABLE1_1_FK = prior id
)
请注意,架构无法更改,我会避免更改CASCADE行为(现在它不行动)。
感谢。
答案 0 :(得分:2)
请您回复一下,以便我接受吗?
你走了:
您是否尝试在CONNECT BY子句中添加OR TABLE1_2_FK = PRIOR ID
?