Oraclejob regularly deletes a record

Source: Internet
Author: User
1. Create the createtablecj_jt_nscpdmdy (IDVARCHAR2 (40) notnullprimarykey, CPBHVARCHAR2 (80) notnull, nsbhva

1. create table cj_jt_nscpdmdy (ID VARCHAR2 (40) not null primary key, CPBH VARCHAR2 (80) not null, nsbh VA

1. Create a table
Create table cj_jt_nscpdmdy
(
ID VARCHAR2 (40) not null primary key,
CPBH VARCHAR2 (80) not null,
Nsbh VARCHAR2 (80) not null,
BZ VARCHAR2 (80)
);

2. Test Data

Insert into cj_jt_nscpdmdy values (1,001,001, 'enabled ');
Insert into cj_jt_nscpdmdy values (2,002,002, 'enabled ');
Insert into cj_jt_nscpdmdy values (3,003,003, 'Disabled ');

3. Create a stored procedure for deleting junk records

Create or replace procedure mypro
Begin
Delete from cj_jt_nscpdmdy where BZ = 'Disabled ';
End;
/
Process created
4. Create a JOB to delete records not enabled in cj_jt_nscpdmdy at midnight on the first day of each month.

Variable job number;
Begin
Dbms_job.submit (: job, 'mypro; ', trunc (last_day (sysdate) + 1), 'trunc (last_day (sysdate) + 1 )');
Commit;
End;
/

//////////////////////////////////////// //////////////////////////
The preceding steps can complete the task. Do not execute it. Otherwise, the job will be started immediately when the job is created.

//////////////////////////////////////// /////////////////////////
5. Run the JOB
Begin
Dbms_job.run (: job );
End;
/
The process has been completed successfully.

6, select * from cj_jt_nscpdmdy;
Expected results are displayed. // The three records are retrieved, but the disabled records are deleted in advance. I don't know why.
7. delete a JOB
Begin
Dbms_job.remove (: job );
End;
/

The process has been completed successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.