Simple instances of jobs in Oracle

Source: Internet
Author: User

Oracle job is a function provided by oracle to regularly execute a stored procedure or package.

Main scenarios
Perform related operations on the background at regular intervals. For example, save the data of one table to another at every night, and 2. Back up the database at regular intervals.

I. Create a test table

  1. SQL>Create table TEST (a date );

The table has been created.
Ii. Create a custom Process

  1. SQL>Create or replace procedure MYPROC
  2. 2 begin
  3. 3 insert into TEST values (sysdate );
  4. 4 end;
  5. 5/
  6. The process has been created.

3. Create a JOB

  1. SQL>Variable job1 number;
  2. SQL>
  3. SQL>Begin
  4. 2 dbms_job.submit (: job1, 'myproc; ', sysdate, 'sysdate + 100'); -- 1/1440 minutes a day, that is, one minute to run the test process
  5. 3 end;
  6. 4/
  7. The PL/SQL process is successfully completed.

4. Run the JOB

  1. SQL>Begin
  2. 2 dbms_job.run (: job1 );
  3. 3 end;
  4. 4/
  5. The PL/SQL process is successfully completed.

V. query a job

  1. SQL>Select to_char (a, 'yyyy/mm/dd hh24: mi: ss') time from TEST;
  2. Time
  3. -------------------
  4. 2001/01/07 23:51:21
  5. 2001/01/07 23:52:22
  6. 2001/01/07 23:53:24

Vi. delete a JOB

  1. SQL>Begin
  2. 2 dbms_job.remove (: job1 );
  3. 3 end;
  4. 4/bitsCN_com
  5. The PL/SQL process is successfully completed.

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

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.