所以我想创建触发器:
CREATE TRIGGER add_primary_key
AFTER INSERT ON CAJ
FOR EACH ROW
WHEN (ID_CAJ IS NULL)
DECLARE
maximum NUMBER;
BEGIN
maximum := SELECT MAX(ID_CAJ) FROM caj;
if (maximum <> 0)
UPDATE caj
SET ID_CAJ = maximum + 1;
WHERE CAJ_ID = NULL
maximum = maximum +1;
END;
出现此错误:
"invalid NEW or OLD specification"
*Cause: An invalid NEW or OLD specification was given for a column.
*Action: Re-specify the column using the correct NEW or OLD specification.
你们知道吗?
我想是Oracle。这是不正确的:
AFTER INSERT OF ID_CAJ
IN caj
INSERT插入行[s]。列列表与此处无关。它应该是ON表名
AFTER INSERT ON CAJ
如果您想要在插入的行具有NULL
值时设置新主键的触发器,请参阅本主题,了解Oracle在Oracle 中使用SEQUENCE
创建带有sequence.nextval的表的常见方法
我想您不应该指定"OF ID_CAJ",因为它在插入触发器之后,并且是关于行而不是列