1

在 JOB SCHEDULER 的 job_action 中,我有以下 SQL

'BEGIN
       ALTER TRIGGER AFTERIUDSETTLEMENTS DISABLE;
       ALTER TRIGGER AFTERIUDLIQUIDATIONSDETAILS DISABLE;
       UPDATE APPOINTSOFCAS A SET INLD = (SELECT COUNT(*) FROM LIQUIDATIONSDETAILS LD WHERE A.CUSTOMERID = LD.CUSTOMERID AND A.ID = LD.APPOINTOFCAID AND A.KINDCONTROLID = LD.KINDCONTROLID);
       UPDATE APPOINTSOFCAS A SET INSD = (SELECT COUNT(*) FROM SETTLEMENTS S WHERE A.CUSTOMERID = S.CUSTOMERID AND A.ID = S.APPOINTOFCAID AND A.KINDCONTROLID = S.KINDCONTROLID);
COMMIT;
       ALTER TRIGGER AFTERIUDSETTLEMENTS ENABLE;
       ALTER TRIGGER AFTERIUDLIQUIDATIONSDETAILS ENABLE;                            
END;'

但运行后作业失败并出现以下错误:

ORA-06550: γραμμή 2, στήλη 29:

PLS-00103:在预期以下情况之一时遇到符号“ALTER”:

 begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier>
 <a double-quoted delimited-identifier> <a bind variable> <<
 συνέχεια close current delete fetch lock insert open
 rollback savepoint set sql execute commit forall merge pipe
οριστική διαγραφή

可以在 JOB SCHEDULER 中禁用或启用触发器吗?

4

1 回答 1

3

ALTER 语句是 DDL,这意味着如果不使用EXECUTE IMMEDIATE就无法在 PL/SQL 块的范围内完成。

这是相当不寻常的,这意味着您的触发器在每个会话中都被禁用,因此如果发生其他任何事情,它们将不会触发任何更改。这是可能的,但这只是感觉不对。

您也可以在一个语句中进行两次更新,这样会更有效率。

begin

   execute immediate 'alter trigger afteriudsettlements disable';
   execute immediate 'alter trigger afteriudliquidationsdetails disable';

   update appointsofcas a 
      set inld = ( select count(*) 
                     from liquidationsdetails ld 
                    where a.customerid = ld.customerid 
                      and a.id = ld.appointofcaid 
                      and a.kindcontrolid = ld.kindcontrolid )
        , insd = ( select count(*) 
                     from settlements s 
                    where a.customerid = s.customerid 
                      and a.id = s.appointofcaid 
                      and a.kindcontrolid = s.kindcontrolid );

   commit;

   execute immediate 'alter trigger afteriudsettlements enable';
   execute immediate 'alter trigger afteriudliquidationsdetails enable';

end;
/
于 2013-09-18T07:40:58.377 回答