我做了一个触发器来更新表“SchemeComp”行,同时插入一个新行。我一次插入多个/批量行,但它抛出一个异常,该行没有被插入。这是我得到的异常:
Error report -
ORA-04091: table ABC009.SchemeComp is mutating, trigger/function may not see it
ORA-06512: at "ABCS009.TrCreateParentChildRelation", line 3
ORA-04088: error during execution of trigger 'ABCS009.TrCreateParentChildRelation' `
字符串
这是我对触发器的查询:
CREATE OR REPLACE TRIGGER "TrCreateParentChildRelation"
AFTER INSERT ON "SchemeComp"
FOR EACH ROW
BEGIN
IF :NEW."ParentComponentCode" IS NOT NULL THEN
UPDATE "SchemeComp" sc1
SET sc1."ParentId" = (
SELECT sc2."Id"
FROM "SchemeComp" sc2
WHERE sc1."ParentComponentCode" = sc2."ComponentCode"
AND sc1."SchemeId" = sc2."SchemeId"
)
WHERE sc1."ParentComponentCode" IS NOT NULL
AND sc1."SchemeId" = :NEW."SchemeId";
END IF;
END;
/
型
下面是我的插入查询,我一次运行两个插入查询。
INSERT INTO "SchemeComp" ("ParentId", "ComponentCode", "ParentComponentCode", "ComponentName", "SchemeId", "EntryDate", "IsActive", "CreatedBy", "IP")
VALUES (null, 'B', null, 'Tribal Area Sub Plan', '0R55', SYSTIMESTAMP, '1', 'BANKADMIN002', '::1');
INSERT INTO "SchemeComp" ("ParentId", "ComponentCode", "ParentComponentCode", "ComponentName", "SchemeId", "EntryDate", "IsActive", "CreatedBy", "IP")
VALUES (null, 'B.1', 'B', 'Recurring', '0R55', SYSTIMESTAMP, '1', 'BANKADMIN002', '::1');
型
1条答案
按热度按时间unguejic1#
你不能 * 直接 *
update
(或选择值)表,你插入行,因为它是-如错误所说- * 变异 *。但是,如果你重写trigger,让你先选择所需的值,然后更新它,那么它应该是好的。像这样的东西:
字符串