存储过程中的 DBA 编程工作

发布于 2024-10-20 02:09:00 字数 1545 浏览 2 评论 0原文

我对编程有点陌生,所以非常感谢任何帮助。

下面是我的存储过程的代码,用于删除表并创建一个每小时运行的 DBA 作业。

CREATE OR REPLACE procedure DELETE_My_TABLE(myschema varchar2) as 
BEGIN
    BEGIN
        execute immediate 'delete from '||myschema||'.mytable where clause;';
    END;
        BEGIN
            DBMS_SCHEDULER.create_program (
            program_name        => 'DELETE_My_TABLE',
            program_type        => 'STORED_PROCEDURE',
            program_action      => 'execute DELETE_My_TABLE(myschema)',
            number_of_arguments => 1,
            enabled             => FALSE,
            comments            => 'Program to delete table using a stored procedure.');
        DBMS_SCHEDULER.define_program_argument (
        program_name      => 'DELETE_My_TABLE',
        argument_name     => 'myschema',
        argument_position => 1,
        argument_type     => 'VARCHAR2',
        default_value     => 'myschema');

        DBMS_SCHEDULER.enable (name => 'DELETE_My_TABLE');
    END;

    BEGIN
        DBMS_SCHEDULER.create_schedule (
        schedule_name   => 'DELETE_My_TABLE',
        start_date      => SYSTIMESTAMP,
        repeat_interval => 'freq=hourly; byminute=0',
        end_date        => NULL,
        comments        => 'Hourly Job to purge SEARCH_TEMP_TABLE');
    END;
END;
/

问题:

ERROR at line 1:
ORA-00920: invalid relational operator
ORA-06512: at "MYSCHEMA.DELETE_My_TABLE", line 4
ORA-06512: at line 1

逻辑(和语法)有效吗?

I am a little new to programming, so any help is appreciated.

Find below the code of my stored proc to delete a table and also create a DBA job which will run on a hourly basis.

CREATE OR REPLACE procedure DELETE_My_TABLE(myschema varchar2) as 
BEGIN
    BEGIN
        execute immediate 'delete from '||myschema||'.mytable where clause;';
    END;
        BEGIN
            DBMS_SCHEDULER.create_program (
            program_name        => 'DELETE_My_TABLE',
            program_type        => 'STORED_PROCEDURE',
            program_action      => 'execute DELETE_My_TABLE(myschema)',
            number_of_arguments => 1,
            enabled             => FALSE,
            comments            => 'Program to delete table using a stored procedure.');
        DBMS_SCHEDULER.define_program_argument (
        program_name      => 'DELETE_My_TABLE',
        argument_name     => 'myschema',
        argument_position => 1,
        argument_type     => 'VARCHAR2',
        default_value     => 'myschema');

        DBMS_SCHEDULER.enable (name => 'DELETE_My_TABLE');
    END;

    BEGIN
        DBMS_SCHEDULER.create_schedule (
        schedule_name   => 'DELETE_My_TABLE',
        start_date      => SYSTIMESTAMP,
        repeat_interval => 'freq=hourly; byminute=0',
        end_date        => NULL,
        comments        => 'Hourly Job to purge SEARCH_TEMP_TABLE');
    END;
END;
/

Issues:

ERROR at line 1:
ORA-00920: invalid relational operator
ORA-06512: at "MYSCHEMA.DELETE_My_TABLE", line 4
ORA-06512: at line 1

Will the logic (and syntax) work?

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

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

发布评论

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

评论(2

硪扪都還晓 2024-10-27 02:09:00

我看到的一个问题是,您需要从 EXECUTE IMMEDIATE 字符串中取出分号:

execute immediate 'delete from '||myschema||'.mytable where clause';
                                                                 ^^
                                                         Removed from here

我想我怀疑这不会解决您眼前的问题,这看起来像是您的 BEGIN ...END 块。

One issue I can see is that you need to take the semi-colon out of the EXECUTE IMMEDIATE string:

execute immediate 'delete from '||myschema||'.mytable where clause';
                                                                 ^^
                                                         Removed from here

thought I suspect this won't solve your immediate problem, which looks like it's your BEGIN ...END blocks.

夏夜暖风 2024-10-27 02:09:00

对于 Oracle Scheduler,您通常创建一个程序一次。接下来,您创建一个将程序作为操作的作业。您可以为该作业指定一个像您在代码中指定的时间表,但您必须选择。您可以创建一个计划并让作业使用它,或者为作业提供自己的重复间隔。

我碰巧知道一本书(掌握 Oracle Scheduler )我写的可能非常有帮助。

For the Oracle Scheduler you normally create a program, once. Next you create a job that has the program as action. You can give that job a schedule like you specified in your code but you have to choose. Either you create a schedule and have the job use it, or you give the job it's own repeat interval.

I happen to know about a book ( Mastering Oracle Scheduler ) that I wrote that could be very helpful.

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