Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

oracle - DBMS_SCHEDULER.CREATE_JOB returning "unknown command"

I am trying to create a simple SQL job in Oracle using SQL Developer. This job will run daily and will execute one stored procedure.

The script is:

   DBMS_SCHEDULER.CREATE_JOB (
            job_name => '"schema1"."jobName"',
            job_type => 'STORED_PROCEDURE',
            job_action => 'schema1.import1.sp_import',
            number_of_arguments => 0,
            start_date => TO_TIMESTAMP_TZ('2021-01-12 14:31:21.000000000 AMERICA/NEW_YORK','YYYY-MM-DD HH24:MI:SS.FF TZR'),
            repeat_interval => 'FREQ=DAILY;BYTIME=144500;BYDAY=MON,TUE,WED,THU,FRI',
            end_date => NULL,
            enabled => FALSE,
            auto_drop => FALSE,
            comments => 'This job will populate date in new table.');   

Upon execution of this I am getting below error:

Error starting at line : 2 in command -
   DBMS_SCHEDULER.CREATE_JOB (
Error report -
Unknown Command

Any idea?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Cause of that error is, I believe, the fact that you didn't enclose DBMS_SCHEDULER.CREATE_JOB into a BEGIN-END block:

begin
  dbms_scheduler.create_job(...);
end;
/

Also, repeat_interval looks wrong (at least, in my 11g). There's no BYTIME - use BYHOUR and BYMINUTE combination instead. Something like this (note that I don't have your procedure):

SQL> BEGIN
  2    DBMS_SCHEDULER.CREATE_JOB (
  3      job_name        => 'test',
  4      job_type        => 'STORED_PROCEDURE',
  5      job_action      => 'p_test',
  6      number_of_arguments => 0,
  7      start_date      => TO_TIMESTAMP_TZ('2021-01-12 14:31:21.000000000 AMERICA/NEW_YORK','YYYY-MM-DD HH24:MI:SS.FF TZR'),
  8      repeat_interval => 'FREQ=DAILY;BYDAY=MON,TUE,WED,THU,FRI;BYHOUR=14;BYMINUTE=45',
  9      end_date        => NULL,
 10      enabled         => FALSE,
 11      auto_drop       => FALSE,
 12      comments        => 'This job will populate date in new table.');
 13  END;
 14  /

PL/SQL procedure successfully completed.

SQL>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...