如何将job_name呈现给DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION

时间:2014-09-17 01:34:53

标签: oracle plsql oracle11g dbms-scheduler

我在向Oracle 11g(11.2.0.1.0)添加电子邮件通知时遇到问题。这似乎是一个错误,但我真的不确定。我尝试使用SQL Developer来构建代码以及来自互联网的示例但是它无法正常工作。

我可以轻松地创建和启用作业:

 BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
            job_name => '"SCHEMA"."test1"',
            job_type => 'PLSQL_BLOCK',
            job_action => 'begin
                           null;
                          end;
                          ',
            auto_drop => FALSE
            );

    DBMS_SCHEDULER.enable(
             name => '"SCHEMA"."test1"');
END;
/

匿名阻止完成

作为预防措施,我删除了工作电子邮件通知 - 这有效。

BEGIN

    DBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION (    
            job_name => '"SCHEMA"."test1"'
             );

end;
/

匿名阻止完成

但是,当我尝试添加电子邮件通知时,就好像找不到对象一样,我在我自己的架构中工作并拥有DBA角色所以我会想到任何应该克服潜在的许可问题(虽然在我自己的架构中我会假设我可以轻松地完成预定的工作)

BEGIN
    DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (    
             job_name => '"SCHEMA"."test1"', 
             recipients => 'email_address@test.com',
             events => 'JOB_BROKEN, JOB_CHAIN_STALLED, JOB_FAILED, JOB_OVER_MAX_DUR, JOB_SCH_LIM_REACHED'
             );
END; 
/

ORA-27476: "SCHEMA.SCHEMA" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 4856
ORA-06512: at "SYS.DBMS_ISCHED", line 7117
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 4030
ORA-06512: at line 3

请注意,它说SCHEMA.SCHEMA好像没有正确读取该行。当我从'"" SCHEMA"。" test1"'到' test1'它仍然不起作用,但是说ORA-27476:" SCHEMA.TEST1"不存在。

我的所有工作都正常工作,并且我已经实现了UTL_MAIL实施,但我真的希望尽可能让oracle的工作变得简单。

1 个答案:

答案 0 :(得分:2)

可能的问题是,默认情况下,Oracle中的对象名称不区分大小写,除非用双引号括起它们。

这是一个测试用例:

SQL> select * from v$version where rownum = 1;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SQL> create user STACKOVERFLOW identified by STACKOVERFLOW;

User created.

SQL> grant connect, create job to STACKOVERFLOW;

Grant succeeded.

SQL> conn STACKOVERFLOW/STACKOVERFLOW

SQL> l
  1  BEGIN
  2      DBMS_SCHEDULER.CREATE_JOB (
  3              job_name => '"STACKOVERFLOW"."test1"',
  4              job_type => 'PLSQL_BLOCK',
  5              job_action => 'begin
  6                             null;
  7                            end;
  8                            ',
  9              auto_drop => FALSE
 10              );
 11      DBMS_SCHEDULER.enable(
 12               name => '"STACKOVERFLOW"."test1"');
 13* END;
SQL> /

PL/SQL procedure successfully completed.

如果您将作业命名为"test1",Oracle将使用小写名称创建它。您可以通过检查目录视图dba_scheduler_jobs

来确认
SQL> select owner, job_name from dba_scheduler_jobs where job_name = 'TEST1';

no rows selected

SQL> select owner, job_name from dba_scheduler_jobs where job_name = 'test1';

OWNER                          JOB_NAME
------------------------------ ------------------------------
STACKOVERFLOW                  test1

因此,这将有效:

SQL> l
  1  BEGIN
  2      DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
  3               job_name => '"STACKOVERFLOW"."test1"',
  4               recipients => 'email_address@test.com',
  5               events => 'JOB_BROKEN, JOB_CHAIN_STALLED, JOB_FAILED, JOB_OVER_MAX_DUR, JOB_SCH_LIM_REACHED'
  6               );
  7* END;
SQL> /

PL/SQL procedure successfully completed.

但这不会:

SQL> l
  1  BEGIN
  2      DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
  3               job_name => '"STACKOVERFLOW".TEST1',
  4               recipients => 'email_address@test.com',
  5               events => 'JOB_BROKEN, JOB_CHAIN_STALLED, JOB_FAILED, JOB_OVER_MAX_DUR, JOB_SCH_LIM_REACHED'
  6               );
  7* END;

SQL> /
BEGIN
*
ERROR at line 1:
ORA-27476: "STACKOVERFLOW.STACKOVERFLOW" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 4921
ORA-06512: at "SYS.DBMS_ISCHED", line 7613
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 4063
ORA-06512: at line 2