1

我对 PL SQL 很陌生,我正在尝试编写一个触发器,它会在表 A 中的字段更新时触发,然后去更新表 B 中的字段。

第二个表可能没有任何相关记录,或者它可能有很多行(在这种情况下,我需要更新所有行)。

根据表 A 中更新的值(称为 HNCMA.AGREEMENT_EOI.STATUS),我想影响表 B 中更新的值(称为 LMD.LM_ACTIVITY_.ACTIVITY_STATUS_CODE)。

这是我到目前为止所得到的,但我收到了这个错误:

PLS-00103:在预期以下之一时遇到符号“=”::=.(@%;

任何帮助将非常感激!!!!

谢谢


CREATE OR REPLACE TRIGGER TR_UPDATE_STATUS

AFTER UPDATE OF STATUS ON HNCMA.AGREEMENTS_EOI
FOR EACH ROW 

DECLARE

VarStatus Varchar(10);
VarStatusCode Int;

BEGIN

if :new.Status = 'Proposed' then VarStatus = 2 else
if :new.Status = 'Recommended' then VarStatus = 5 else
if :new.Status = 'Funded' then VarStatus = 5 else
if :new.Status = 'Completed' then VarStatus = 6 else
if :new.Status = 'Withdrawn' then VarStatus = 34 
end if

UPDATE
(SELECT LMD.LM_ACTIVITY.ACTIVITY_STATUS_CODE
FROM (HNCMA.AGREEMENTS_EOI INNER JOIN HNCMA.PROJECT ON HNCMA.AGREEMENTS_EOI.PROJECTID = HNCMA.PROJECT.PROJECTID) INNER JOIN (LMD.LM_POLYGON_PROJECT_REL INNER JOIN LMD.LM_ACTIVITY ON LMD.LM_POLYGON_PROJECT_REL.LMID = LMD.LM_ACTIVITY.LMID) ON HNCMA.AGREEMENTS_EOI.CASENO = LMD.LM_POLYGON_PROJECT_REL.LOCAL_PROJECT_NAME
WHERE (((HNCMA.PROJECT.CATCHMENT)='Murray') AND ((HNCMA.AGREEMENTS_EOI.CASENO)= :old.CASENO ));) s
Set s.ACTIVITY_STATUS_CODE = varstatuscode


End;

更新*

感谢@heaps 的帮助。我已经修改了我的代码以包含 CASE 函数并修复了我的格式错误。这是我到目前为止所得到的(当我取出更新语句时它可以工作),但我现在收到“SQL 命令未正确结束”错误......

帮助!?!

创建或替换触发器 TR_UPDATE_LMDB_STATUS1

AFTER UPDATE OF STATUS ON HNCMA.AGREEMENTS_EOI
FOR EACH ROW 

DECLARE

VarStatus Varchar(50);
VarStatusCode Int;

BEGIN

VarStatus := :new.status;

CASE varstatus

WHEN 'Proposed' THEN VarstatusCode := 2;
WHEN 'Recommended' THEN VarStatusCode := 5;
WHEN 'Funded' THEN VarStatusCode := 5;
WHEN 'Completed' THEN VarStatusCode := 6;
WHEN 'Withdrawn' THEN VarStatusCode := 34;

END CASE;

UPDATE LMD.LM_ACTIVITY
SET ACTIVITY_STATUS_CODE = VarStatusCode
FROM (HNCMA.AGREEMENTS_EOI INNER JOIN HNCMA.PROJECT ON HNCMA.AGREEMENTS_EOI.PROJECTID = HNCMA.PROJECT.PROJECTID) INNER JOIN (LMD.LM_POLYGON_PROJECT_REL INNER JOIN LMD.LM_ACTIVITY ON LMD.LM_POLYGON_PROJECT_REL.LMID = LMD.LM_ACTIVITY.LMID) ON HNCMA.AGREEMENTS_EOI.CASENO = LMD.LM_POLYGON_PROJECT_REL.LOCAL_PROJECT_NAME
WHERE (((HNCMA.PROJECT.CATCHMENT)='Murray') AND ((HNCMA.AGREEMENTS_EOI.CASENO)= :old.CASENO )) ;

End;
4

1 回答 1

1

将 varstatus=2 替换为 ifVarstatus:=2 并在末尾加上分号,; 然后重试

编辑..为您更新的问题>>

该错误SQL command not properly ended是因为您应该使用UPDATE命令进行检查

似乎FROM更新中的问题子句,因为我认为最好尝试使用 UPDATE... WHERE EXISTS.. orMERGE命令,oracle 不支持 UPDATE 中的 FROM 子句,您可以将其用作查询

于 2013-01-23T08:22:03.753 回答