我正在使用Oracle版本12c。我创建了一个触发器,该触发器应该创建一个审计条目,因此将其称为before update
(我简化了以下示例以使其易于阅读-错误保持不变)。我正在对clean db
使用ant目标(整个recreate
目标的第一步)。 clean db
步骤如下:
BEGIN
FOR c IN (SELECT object_name FROM user_procedures) LOOP
EXECUTE IMMEDIATE ('DROP PROCEDURE "' || c.object_name || '"');
END LOOP;
END;
/
user_tables
和user_views
还有两个循环(为简洁起见,呼叫顺序为user_tables
,然后依次为user_views
和user_procedures
)。当我将触发器放入迁移脚本中时(我正在使用flyway):
CREATE OR REPLACE TRIGGER trg_car_audit
BEFORE UPDATE
ON CAR
FOR EACH ROW
BEGIN
INSERT INTO CAR (ID, MANUFACTURER, MODEL)
VALUES (:OLD.ID, :OLD.MANUFACTURER, :OLD.MODEL);
END;
/
在整个recreate db
蚂蚁目标中,它到达了clean db
目标中的点,我得到:
Failed to execute: BEGIN FOR c IN (SELECT object_name FROM user_procedures) LOOP EXECUTE IMMEDIATE ('DROP PROCEDURE "' || c.object_name || '"'); END LOOP; END;
java.sql.SQLSyntaxErrorException: ORA-04043: object BIN$fZDGeHfvC9bhUiQJFawHpg==$0 doesn't exist
当我执行:SELECT * FROM user_procedures
时,它会给我:
OBJECT_NAME PROCEDURE_NAME OBJECT_ID SUBPROGRAM_ID OVERLOAD OBJECT_TYPE AGGREGATE PIPELINED IMPLTYPEOWNER IMPLTYPENAME PARALLEL INTERFACE DETERMINISTIC AUTHID ORIGIN_CON_ID
------------------------------- -------------- --------- ------------- --------- ------------ ---------- ---------- ------------- ------------ -------- ---------- ------------- ------- -------------
BIN$fZDGeHfvC9bhUiQJFawHpg==$0 NULL 120236 1 NULL TRIGGER NO NO NULL NULL NO NO NO DEFINER 0
我只能通过purge recyclebin;
摆脱它。
bin*
项放入
user_procedures
表?我拥有DROP ANY PROCEDURE
系统特权(我确实有其他过程,可以被完全丢弃)
答案 0 :(得分:4)
您的过程尝试删除已删除的内容。您可以识别出来,因为其名称以“ BIN $”开头。清除后,问题消失了。
解决方案是过滤不以'BIN $'开头的object_name
BEGIN
FOR c IN (SELECT object_name FROM user_procedures
WHERE object_name NOT LIKE 'BIN$%' ) LOOP
EXECUTE IMMEDIATE ('DROP PROCEDURE "' || c.object_name || '"');
END LOOP;
END;
/