我正在尝试在 Oracle 数据库中创建一个作业,每五分钟刷新一次物化 View 。以下是我编写的代码:
BEGIN
SYS.DBMS_SCHEDULER.create_job(
job_name => 'refresh_cop_union',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN DBMS_SNAPSHOT.REFRESH(''COP_UNION'',''C''); END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'freq=minutely;interval=5',
end_date => NULL,
enabled => TRUE,
auto_drop => FALSE,
comments => 'Refresh COP_UNION matview'
);
END;
/
当我执行它时,出现以下错误:
Error report -
ORA-27477: "MASTER_DB"."REFRESH_COP_UNION" already exists
ORA-06512: at "SYS.DBMS_ISCHED", line 175
ORA-06512: at "SYS.DBMS_SCHEDULER", line 288
ORA-06512: at line 2
27477. 00000 - "\"%s\".\"%s\" already exists"
*Cause: An attempt was made to create an object with a name that has already been used by another object in the same schema.
*Action: Reissue the command using a different name or schema.
所以我的数据库中似乎有另一个同名的对象,可能是另一项工作。因此我尝试执行以下代码来删除它并用我的新版本替换它:
BEGIN
sys.dbms_scheduler.drop_job(job_name => 'refresh_cop_union');
END;
/
但是失败并出现以下错误:
Error report -
ORA-27475: unknown job "MASTER_DB"."REFRESH_COP_UNION"
ORA-06512: at "SYS.DBMS_ISCHED", line 274
ORA-06512: at "SYS.DBMS_SCHEDULER", line 753
ORA-06512: at line 2
27475. 00000 - "unknown %s \"%s\".\"%s\""
*Cause: The specified object did not exist, privileges were not granted, or the object was of the wrong type.
*Action: Specify an object of the correct type on which you have privileges.
这基本上表明我尝试删除的对象不存在。这怎么可能?我怎样才能找到这个对象,看看它是什么并最终删除它?
我还检查了数据库中可能具有相似名称的所有对象:其他表、 View 、触发器,但我什么也没发现。
我试图列出我拥有的所有工作,以便找到我的工作:
SELECT * FROM USER_JOBS
WHERE WHAT LIKE '%COP_UNION%';
但是什么也没出现。有什么想法吗?
最佳答案
您必须选择USER_SCHEDULER_JOBS
,而不是USER_JOBS
:
SELECT *
FROM USER_SCHEDULER_JOBS
where JOB_NAME LIKE '%COP_UNION%';
DBMS_SCHEDULER
是(新)调度程序作业,而(旧)作业由包 DBMS_JOB
维护
看起来调度程序作业不得与任何其他对象同名。检查
SELECT *
FROM ALL_OBJECTS
WHERE OBJECT_NAME LIKE '%COP_UNION%';
并选择了不同的名称。
似乎是 Oracle 中的一个错误 ( Bug 4055853 )。根据 Oracle 的说法,解决方案/解决方法是
Changing the job name to be different than any object owned by the user will work around the problem.
关于database - Oracle创建批处理作业时出错: already exists?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53315939/