--登錄sys用戶,創(chuàng)建一個(gè)測(cè)試用戶,權(quán)限可以給大點(diǎn)
SQL> create user test identified by xxxxx;
SQL> grant connect to test;
SQL> grant resource to test;
SQL> grant dba to test;
--登錄test用戶,開始測(cè)試
--建個(gè)測(cè)試表
create table test_table(id int, time timestamp);
--創(chuàng)建Job
begin
dbms_scheduler.create_job(
?? ?job_name => 'test_job',
?? ?job_type => 'PLSQL_BLOCK',
?? ?job_action => 'insert into test_table
????????????????? (select nvl(max(id),0)+1, systimestamp from test_table, dual);', --nvl函數(shù)同SQLServer的isnull函數(shù)
?? ?start_date => null, --一激活,就開始
?? ?repeat_interval => 'FREQ=SECONDLY;INTERVAL=10');
end;
FREQ用來(lái)指定間隔的時(shí)間周期,可選參數(shù)有:YEARLY,MONTHLY,WEEKLY,DAILY,HOURLY,MINUTELY,SECONDLY。
--光創(chuàng)建沒用,還需要激活;也可以在創(chuàng)建時(shí),直接把enable屬性設(shè)置為true(enabled => true)
select job_name, enabled, run_count from user_scheduler_jobs;
JOB_NAME?????????????????????? ENABL? RUN_COUNT
------------------------------ ----- ----------
TEST_JOB?????????????????????? FALSE????????? 0
begin
dbms_scheduler.enable('test_job');
end;
--查看效果
select id, to_char(time,'HH24:MI:SS:FF3') from test_table;
?????? ID? TO_CHAR(TIME,'HH24
---------- ------------------
???????? 1 16:13:29:542
???????? 2 16:13:39:506
???????? 3 16:13:49:109
???????? 4 16:13:59:097
???????? 5 16:14:09:109
???????? 6 16:14:19:103
???????? 7 16:14:29:101
???????? 8 16:14:39:099
???????? 9 16:14:49:105
??????? 10 16:14:59:100
--停止任務(wù)
begin
dbms_scheduler.disable('test_job');
end;
--刪除任務(wù)
begin
dbms_scheduler.drop_job('test_job');
end;