如何使用ORACLE JOB SCHEDULER更改禁用或启用触发器

时间:2013-09-18 06:37:49

标签: sql oracle11g

在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中禁用或启用触发器吗?

1 个答案:

答案 0 :(得分:2)

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;
/