如何使用 DBMS_SCHEDULER.CREATE_JOB 过程执行过程

发布于 2024-08-12 03:00:01 字数 1827 浏览 6 评论 0原文

我想创建一个作业,该作业将在给定日期删除数据库对象。作业创建正常,但过程未执行。尝试单独执行该过程并且它有效。

以下是创建作业的代码

v_jobnam := v_objnam; 
                v_jobnam := DBMS_SCHEDULER.generate_job_name (v_jobnam);  

 v_startdate := to_timestamp(v_startdate); 
     select sysdate + (v_delhrs/1440) 
        into v_startdate
        from dual;

 DBMS_SCHEDULER.CREATE_JOB(job_name => v_jobnam, job_type => 'PLSQL_BLOCK', JOB_ACTION => 'BEGIN DROP_OBJ1(' || v_objnam|| ', ' || v_objtyp || ', '|| v_schema || ',' || v_objid ||'); END;', start_date => SYSTIMESTAMP, repeat_interval => 'freq=secondly; bysecond=0', end_date => NULL, enabled => TRUE, comments => 'Calls PLSQL once');

,其中 v_delhrs 是一个数字。 这是该过程的代码:

  PROCEDURE DROP_OBJ1
    (
        p_objnam       IN   CHAR,
        p_objtyp       IN   CHAR,
        p_copyto       IN   ALL_OBJECTS.OWNER%TYPE,
        p_objid        IN   NUMBER
    )
    IS

       v_objnam       VARCHAR2 (30);
       v_objtyp       VARCHAR2 (30);
       v_copyto       VARCHAR2 (30);
       v_objid        NUMBER (3);


    BEGIN

            v_objnam := UPPER (p_objnam);
            v_objtyp := UPPER (p_objtyp);
            v_copyto := UPPER (p_copyto);
            v_objid  := p_objid;
            --v_copyby := UPPER (p_copyby);

             EXECUTE IMMEDIATE ( ' DROP '
                               || v_objtyp
                               || ' '
                               || v_copyto
                               || '.'
                               || v_objnam
                               );

             EXECUTE IMMEDIATE ( ' DELETE FROM COPY_OBJ_DET WHERE OBJ_ID = '
                                || v_objid
                                );


         COMMIT;

    END;

我知道这是一个非常小的问题。 提前感谢各位大师。

干杯!

I want to create a job that would drop a database object at a given date. The job created all right but the procedure is not executed. Tried executing the procedure alone and it works.

Here's the code for the create job

v_jobnam := v_objnam; 
                v_jobnam := DBMS_SCHEDULER.generate_job_name (v_jobnam);  

 v_startdate := to_timestamp(v_startdate); 
     select sysdate + (v_delhrs/1440) 
        into v_startdate
        from dual;

 DBMS_SCHEDULER.CREATE_JOB(job_name => v_jobnam, job_type => 'PLSQL_BLOCK', JOB_ACTION => 'BEGIN DROP_OBJ1(' || v_objnam|| ', ' || v_objtyp || ', '|| v_schema || ',' || v_objid ||'); END;', start_date => SYSTIMESTAMP, repeat_interval => 'freq=secondly; bysecond=0', end_date => NULL, enabled => TRUE, comments => 'Calls PLSQL once');

where v_delhrs is a number.
Here's the code for the procedure:

  PROCEDURE DROP_OBJ1
    (
        p_objnam       IN   CHAR,
        p_objtyp       IN   CHAR,
        p_copyto       IN   ALL_OBJECTS.OWNER%TYPE,
        p_objid        IN   NUMBER
    )
    IS

       v_objnam       VARCHAR2 (30);
       v_objtyp       VARCHAR2 (30);
       v_copyto       VARCHAR2 (30);
       v_objid        NUMBER (3);


    BEGIN

            v_objnam := UPPER (p_objnam);
            v_objtyp := UPPER (p_objtyp);
            v_copyto := UPPER (p_copyto);
            v_objid  := p_objid;
            --v_copyby := UPPER (p_copyby);

             EXECUTE IMMEDIATE ( ' DROP '
                               || v_objtyp
                               || ' '
                               || v_copyto
                               || '.'
                               || v_objnam
                               );

             EXECUTE IMMEDIATE ( ' DELETE FROM COPY_OBJ_DET WHERE OBJ_ID = '
                                || v_objid
                                );


         COMMIT;

    END;

I know its a very minor problem.
Thanks in advance gurus.

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖 2024-08-19 03:00:01

在我看来,您在 DBMS_JOBS 设置调用中错过了一些引号。

试试这个:

DBMS_SCHEDULER.CREATE_JOB(job_name        => v_jobnam,
                          job_type        => 'PLSQL_BLOCK',
                          JOB_ACTION      => 'BEGIN DROP_OBJ1(''' || v_objnam 
                                             || ''', ''' || v_objtyp || ''', '''
                                             || v_schema || ''',' || v_objid 
                                             || '); END;',
                          start_date      => SYSTIMESTAMP,
                          repeat_interval => 'freq=secondly; bysecond=0',
                          end_date        => NULL,
                          enabled         => TRUE,
                          comments        => 'Calls PLSQL once');

如果这不是解决方案,我将在数据库上设置您的代码并亲自尝试。

It apears to me that you have missed some quote marks in the DBMS_JOBS setup call.

Try this:

DBMS_SCHEDULER.CREATE_JOB(job_name        => v_jobnam,
                          job_type        => 'PLSQL_BLOCK',
                          JOB_ACTION      => 'BEGIN DROP_OBJ1(''' || v_objnam 
                                             || ''', ''' || v_objtyp || ''', '''
                                             || v_schema || ''',' || v_objid 
                                             || '); END;',
                          start_date      => SYSTIMESTAMP,
                          repeat_interval => 'freq=secondly; bysecond=0',
                          end_date        => NULL,
                          enabled         => TRUE,
                          comments        => 'Calls PLSQL once');

If this is not the solution I will setup your code on a database and try it myself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文