Home > Database > Mysql Tutorial > Oracle job 定时删除某条记录

Oracle job 定时删除某条记录

WBOY
Release: 2016-06-07 16:58:03
Original
920 people have browsed it

1,创建表create table CJ_JT_NSRCPDMDY(ID VARCHAR2(40) not null primary key, CPBH VARCHAR2(80) not null,NSRBH VA

1,创建表
create table CJ_JT_NSRCPDMDY
(
ID     VARCHAR2(40)  not null primary key,
CPBH   VARCHAR2(80)  not null,
NSRBH  VARCHAR2(80)  not null,
BZ     VARCHAR2(80)
);

2,测试数据

insert into CJ_JT_NSRCPDMDY values(1,001,001,'启用');
insert into CJ_JT_NSRCPDMDY values(2,002,002,'启用');
insert into CJ_JT_NSRCPDMDY values(3,003,003,'不启用');

3,创建一个删除垃圾记录的存储过程

create or replace procedure mypro as
begin
delete from CJ_JT_NSRCPDMDY where BZ = '不启用';
end;
/
过程已创建
4,,创建JOB,实现每个月第一天的午夜12点删除CJ_JT_NSRCPDMDY中不启用的记录。

variable job number;
begin
dbms_job.submit(:job,'mypro;',trunc(last_day(sysdate)+1),'trunc(last_day(sysdate)+1)');
commit;
end;
/

//////////////////////////////////////////////////////////////////
以上即可完成任务,不要往下执行啦。否则,创建作业时,就马上启动作业了。

/////////////////////////////////////////////////////////////////
5,运行JOB
begin
dbms_job.run(:job);
end;
/
过程已成功完成

6,select * from CJ_JT_NSRCPDMDY;
得到预期结果//这个地方应该是查出来3条记录才对,可是已经把不启用的记录提前删除啦。不知道为什么。
7、删除JOB
begin
dbms_job.remove(:job);
end;
/

过程已成功完成

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template