ON DELETE SET <值> </value>

时间:2014-10-31 10:16:25

标签: oracle alter-table

我是数据库查询执行的新手。这是我的查询 -

ALTER TABLE TABLE123 ADD (
    CONSTRAINT TABLE_CONSTRAINT
    FOREIGN KEY (TABLE_ID) 
    REFERENCES PARENT_TABLE (TABLE_ID)
    ON DELETE SET 0
);

当我执行此操作时,我收到此错误消息 -

Error starting at line 5 in command:
ALTER TABLE TABLE123 ADD (
    CONSTRAINT TABLE_CONSTRAINT
    FOREIGN KEY (TABLE_ID) 
    REFERENCES PARENT_TABLE (TABLE_ID)
    ON DELETE SET 0
);
Error report:
SQL Error: ORA-00908: missing NULL keyword
00908. 00000 -  "missing NULL keyword"
*Cause:    
*Action:

然后我尝试了这个 -

ALTER TABLE TABLE123 MODIFY TABLE_ID DEFAULT 0 NOT NULL REEFRENCES PARENT_TABLE (TABLE_ID) ON DELETE SET DEFAULT;

我收到了此错误消息 -

Error report:
SQL Error: ORA-03001: unimplemented feature
03001. 00000 -  "unimplemented feature"
*Cause:    This feature is not implemented.
*Action:   None.

1 个答案:

答案 0 :(得分:0)

Oracle的on delete子句仅支持set null。如果要设置不同的值,则必须自己在触发器中实现它:

CREATE TRIGGER parent_table_del_tr
BEFORE DELETE ON parent_table
FOR EACH ROW
BEGIN
    UPDATE table123
    SET    table_id = 0
    WHERE  table_id = :OLD.table_id;
END;
/