我可以暂时禁用oracle存储过程中的触发器吗?
示例(伪代码):
MyProcedure{ disable MyTrigger; //doStuff enable MyTrigger; };
thx提前.
朱塞佩
您可以使用EXECUTE IMMEDIATE语法通过动态sql发出DDL,例如“ALTER TRIGGER”语句.
对此的描述如下:
http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10807/13_elems017.htm
PROCEDURE myProcedure IS BEGIN EXECUTE IMMEDIATE 'ALTER TRIGGER triggername DISABLE'; -- Do work EXECUTE IMMEDIATE 'ALTER TRIGGER triggername ENABLE'; EXCEPTION WHEN OTHERS THEN -- Handle Exceptions END myProcedure;
如果您愿意,也可以使用VARCHAR变量构建动态sql:
PROCEDURE myProcedure IS v_triggername VARCHAR2(30) := 'triggername'; BEGIN EXECUTE IMMEDIATE 'ALTER TRIGGER '||v_triggername||' DISABLE'; -- Do work EXECUTE IMMEDIATE 'ALTER TRIGGER '||v_triggername||' ENABLE'; EXCEPTION WHEN OTHERS THEN -- Handle Exceptions END myProcedure;
如果你这样做,那么你也应该查看包DBMS_ASSERT来包装triggername并帮助强化你的代码以防止sql注入攻击.