--创建表空间,系统用户建立 create tablespace tstest datafile 'D:\oraclexe\oradata\XE\tstest01.dbf' size 100m autoextend on next 50m maxsize 1000m; --删除表空间 DROP tablespace tstest INCLUDING CONTENTS AND DATAFILES; --创建用户 create user test identified by test default tablespace tstest temporary tablespace TEMP; grant connect,dba,resource to test ; --删除用户 drop user test cascade; --创建表 CREATE TABLE test ( id VARCHAR2(100) PRIMARY KEY, name VARCHAR2(100), age VARCHAR2(100), sex VARCHAR2(100) ); --创建一个存储过程用来删除表中过期数据 CREATE OR REPLACE PROCEDURE MYPROC IS BEGIN insert into test(id,name,age,sex) values (sysdate,'tom','12','boy'); END; / --创建JOB variable job1 number; begin dbms_job.submit(:job1,'MYPROC;',sysdate,'sysdate+1/1440'); commit; end; / --创建job,每天1440分钟,即一分钟运行test过程一次 variable job1 number; begin dbms_job.submit(:job1,'INSERT_EXPIRY_DATAS;',sysdate,'sysdate+1/1440'); end; / --运行job begin dbms_job.run(:job1); end; / begin dbms_job.run(:job1); end; / --删除JOB begin dbms_job.remove(:job1); end; / -------------------------------------------------------------------- variable job1 number; begin sys.dbms_job.submit (job => :job1, what => 'INSERT_EXPIRY_DATAS;', next_date => trunc(sysdate)+23/24, interval => trunc(sysdate,'mi')+1/(24*60)); commit; end; --定义一个数字型变量 declare job1 number; begin dbms_job.submit(:job1,'test;',sysdate,'sysdate+1/1440'); end; / variable jobno number; begin dbms_job.submit(:jobno, 'statspack.snap;', trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno); commit; end; print jobno variable job1 number; begin sys.dbms_job.submit (job => :job1, what => 'INSERT_EXPIRY_DATAS;', next_date => trunc(sysdate)+23/24, interval => trunc(sysdate,'mi')+1/(24*60)); commit; end; begin sys.dbms_job.submit(job => :job, what => 'check_err;', next_date => trunc(sysdate)+23/24, interval => 'trunc(next_day(sysdate,''星期五''))+23/24'); commit; end; 其中:job是系统自动产生编号,check_err是我的一个过程,next_date设置下次执行时间,这里是今天晚上23:00,interval设置时间间隔,多久执行一次,这里是每周的星期五晚上23:00,函数next_day返回日期中包含指定字符的日期,trunc 函数去掉日期里的时间,也就是得到的是某天的00:00,时间是以天为单位的所以要得到某某点某某分,就需要分数: 1/24 一小时; 1/1440 一分; 1/3600 一秒;