--History表定期清理
drop procedure pHISTORYclear;
create or replace procedure pHISTORYclear
as
begin
delete from history where trunc(start_time)<trunc(sysdate)-64;
commit;
end;
/--添加定时清理任务History表定期清理,每月一号的2点执行.
declare
i number:=0;
select count(*) into i from all_jobs j where j.what='pHISTORYclear;';
if i>0 then
begin 
variable jb number
    dbms_job.submit(:jb,'pHISTORYclear;',sysdate,'LAST_DAY(trunc(SYSDATE))+1+2/24');
end;end if;
/这样写有什么问题么?在SQL plus里执行就是好几个错误...

解决方案 »

  1.   

    楼主D问题与标题不符..
    查询数据库存在的Job:
    select * from user_jobs;
    select * from dba_jobs;
      

  2.   

    呃,刚开始是那个问题后来查到了  但是改了之后发现执行不了....单独select count(*) 是可以执行的  但是加了变量之后就不行了 
    各位帮个忙
      

  3.   

    SQL代码如下,供参考.declare
      i number:=0;
    begin
      select count(*) into i from all_jobs j where j.what='pHISTORYclear;';
      if i>0 then
        variable jb number;
        begin
          dbms_job.submit(:jb,'pHISTORYclear;',sysdate,'LAST_DAY(trunc(SYSDATE))+1+2/24');
          commit;
        end;
      end if;
    end;
      

  4.   

    查询数据库中已经存在的job:
    select * from user_jobs;
    select * from all_jobs;
    select * from dba_jobs;
      

  5.   


    declare
      i  number:=0;
      jb number;
    begin
      select count(*) into i from all_jobs j where j.what='pHISTORYclear;';
      if i>0 then
        begin
          dbms_job.submit(:jb,'pHISTORYclear;',sysdate,'LAST_DAY(trunc(SYSDATE))+1+2/24');
          commit;
        end;
      end if;
    end;
    /
      

  6.   

    ORA-06550: line 6, column 10:
    PLS-00103: Encountered the symbol "JB" when expecting one of the following:
    := . ( @ % ;
    ORA-06550: line 10, column 5:
    PLS-00103: Encountered the symbol "IF" when expecting one of the following:
    ;
      

  7.   

    按6楼执行就通过了....这是什么情况呢?是说不能用variable 么?
      

  8.   


    是哪里的问题?为什么不能使用variable  ?但是如果直接写
    variable jb number
    begin 
        dbms_job.submit(:jb,'pEIT_HISTORYclear;',sysdate,'LAST_DAY(trunc(SYSDATE))+1+2/24');
    end;这样就没问题,number后面没有分号
      

  9.   

    楼主可看一下PL/SQL关于块的内容,
    块的declare部分是变量定义,
    而后在begin ... end;之间不可再定义变量.