1
CREATE OR REPLACE TRIGGER PROCESS_POPULATE_INSTANCE
AFTER INSERT OR UPDATE ON PROCESS_INSTANCE
FOR EACH ROW
DECLARE
 InstanceExists NUMBER;
BEGIN
 SELECT COUNT(*)
 INTO InstanceExists
 FROM TEST_PROCESSDATA
 WHERE TEST_PROCESSDATA.PROCESS_INSTANCE_ID = :NEW.INSTANCE_ID ;

 IF ( InstanceExists > 0 ) THEN
UPDATE TEST_PROCESSDATA SET PROCESS_STATUS =:NEW.STATUS WHERE PROCESS_INSTANCE_ID = NEW.INSTANCE_ID;
 ELSIF 
 INSERT INTO TEST_PROCESSDATA (PROCESS_INSTANCE_ID,PROCESS_STATUS, STARTED_TIME) VALUES (:NEW.INSTANCE_ID,:NEW.STATUS,:NEW.START_TIME);
 END IF;
END PROCESS_POPULATE_APPDATA; 

在执行上述触发器时,我收到以下错误:

错误(12,2):PLS-00103:在预期以下情况之一时遇到符号“INSERT”:(-+ case mod new not null continue avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval
日期管道
错误(13,2):PLS-00103:遇到符号“END”

4

2 回答 2

2

除了Ravindra bagale已经指出的内容之外,我还要添加以下内容:

第一的。在声明中

UPDATE TEST_PROCESSDATA SET PROCESS_STATUS =:NEW.STATUS 
 WHERE PROCESS_INSTANCE_ID = NEW.INSTANCE_ID;

:前面缺少冒号NEW.INSTANCE_ID

第二。您可能会考虑使用 ofmerge语句而不是IF .. THEN .. ELSE.. END IF构造和附加select语句。例如。

create or replace trigger process_populate_instance     
after insert or update on process_instance 
for each row
begin

   merge into test_processdata
   using dual
     on (process_instance_id = :new.instance_id)
   when matched
    then update
            set process_status =:new.status
   when not matched
   then insert (process_instance_id,process_status, started_time) 
        values (:new.instance_id,:new.status,:new.start_time);

end;
于 2012-10-08T07:07:33.793 回答
1

在这里使用ELSE instead of ELSIF
你使用了elseif,但没有使用else,你不能在没有else的情况下使用elseif,
当有两种以上的方式时你可以使用elsif。

IF ( InstanceExists > 0 ) THEN
UPDATE TEST_PROCESSDATA SET PROCESS_STATUS =:NEW.STATUS WHERE PROCESS_INSTANCE_ID = NEW.INSTANCE_ID;
 ELSE 
 INSERT INTO TEST_PROCESSDATA (PROCESS_INSTANCE_ID,PROCESS_STATUS, STARTED_TIME) VALUES (:NEW.INSTANCE_ID,:NEW.STATUS,:NEW.START_TIME);
 END IF;
END PROC
于 2012-10-08T06:31:40.843 回答