Oracle DB: Scheduled job failing with error: ORA-06576: not a valid function or procedure name

Oracle DB: Scheduled job failing with error: ORA-06576: not a valid function or procedure name

我正在尝试在 Oracle DB 中创建计划作业,我需要从中执行存储过程。

我创建了如下程序:

CREATE OR REPLACE PROCEDURE "delete_old_transactions" AS
BEGIN
  DELETE from EVENT_JOURNAL where EVENT_JOURNAL.WRITE_TIMESTAMP < (((SYSDATE-CAST(TO_TIMESTAMP_TZ('01-01-1970 00:00:00+00:00', 'DD-MM-YYYY HH24:MI:SS TZH:TZM') as date)) * 24 * 60 * 60 * 1000) - (4 * 24 * 60 * 60 * 1000));
  DELETE from SNAPSHOT where SNAPSHOT.CREATED < (((SYSDATE-CAST(TO_TIMESTAMP_TZ('01-01-1970 00:00:00+00:00', 'DD-MM-YYYY HH24:MI:SS TZH:TZM') as date)) * 24 * 60 * 60 * 1000) - (4 * 24 * 60 * 60 * 1000));
END;

存储过程编译正常并成功创建。

我创建了这样的预定作业:

BEGIN
  DBMS_SCHEDULER.CREATE_JOB (
   job_name           =>  'delete_old_transactions_job',
   job_type           =>  'STORED_PROCEDURE',
   start_date         =>  SYSTIMESTAMP,
   enabled            =>  true,
   job_action         =>  'delete_old_transactions',
   repeat_interval    =>  'FREQ=MINUTELY;INTERVAL=2;',
   job_class          =>  'DEFAULT_JOB_CLASS',
   comments           =>  'Job for deleting old transactions.');
END;

计划的作业也已创建并按需要每 2 分钟执行一次,但执行失败并且 returns 出现错误:

ORA-06576: not a valid function or procedure name.

这是错误的:

CREATE OR REPLACE PROCEDURE "delete_old_transactions" 
                            -                       -
                            this                    this

为什么要用双引号? 删除它们。在 Oracle 中,所有内容都以大写形式存储在数据字典中,但您可以以任何方式引用它们(upper/lower/mixed 大小写)。

但是,如果您在创建对象时使用双引号,则每次引用这些对象时都必须使用相同的双引号并完全匹配字母大小写。

因此,最简单的选择是重新创建过程,但这次删除双引号。

或者,将双引号放入 DBMS_SCHEDULER:

job_action         =>  '"delete_old_transactions"',

但这不是什么好主意。

也许这将有助于理解 oracle 如何处理对象名称的大小写敏感性。在这里,我使用 table 个名称,只是为了更简单的演示。但这同样适用于所有对象名称 - table 空格、table、列、函数、过程、包等

密切关注 table 姓名的处理:

SQL> conn scott/tiger@pdb01
Connected.
SQL> --
SQL> select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

1 row selected.

SQL> --
SQL> -- Create mixed-case table
SQL> create table "MyDemo"
  2     (col1 varchar2(20))
  3  ;

Table created.

SQL> insert into "MyDemo" values ('mixed case');

1 row created.

SQL> -- create default case table
SQL> create table MyDemo
  2     (col1 varchar2(20));

Table created.

SQL> insert into MyDemo values ('default');

1 row created.

SQL> --
SQL> select table_name
  2  from user_tables
  3  where upper(table_name)='MYDEMO';

TABLE_NAME
--------------------
MyDemo
MYDEMO

2 rows selected.

SQL>
SQL> select * from mydemo;

COL1
--------------------
default

1 row selected.

SQL> select * from MyDemo;

COL1
--------------------
default

1 row selected.

SQL> select * from "MyDemo";

COL1
--------------------
mixed case

1 row selected.

SQL> -- clean up
SQL> drop table mydemo;

Table dropped.

SQL> drop table "MyDemo";

Table dropped.

SQL> --
SQL> spo off
SQL> edit demo.log
SQL> insert into MyDemo values ('default');

1 row created.

SQL> --
SQL> select table_name
  2  from user_tables
  3  where upper(table_name)='MYDEMO';

TABLE_NAME
--------------------
MyDemo
MYDEMO

2 rows selected.

SQL>
SQL> select * from mydemo;

COL1
--------------------
default

1 row selected.

SQL> select * from MyDemo;

COL1
--------------------
default

1 row selected.

SQL> select * from "MyDemo";

COL1
--------------------
mixed case

1 row selected.

SQL> -- clean up
SQL> drop table mydemo;

Table dropped.

SQL> drop table "MyDemo";

Table dropped.