所以我想创建触发器:
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.
你们有什么想法吗?
答案 0 :(得分:3)
AFTER INSERT OF ID_CAJ
IN caj
INSERT插入行[s]。列列表与此处无关。它应该是ON表名
AFTER INSERT ON CAJ
如果您想要在插入的行具有NULL
值的情况下设置新主键的触发器,请参阅此主题以了解Oracle使用SEQUENCE
create table with sequence.nextval in oracle
答案 1 :(得分:1)
我想你不应该指定&#34; OF ID_CAJ&#34;因为它是在插入触发器之后,它是关于行,而不是列