You are on page 1of 6

SQL> create table test

2 (empno number,
deptno number);
Table created.
SQL> create sequence s
2 increment by 100

3 start with 7000

4 maxvalue 50000

5 nocache

6 nocycle;
Sequence created.
SQL>
SQL> ed
Wrote file afiedt.buf
1 create sequence s2
2 increment by 10

3 start with 10
4 maxvalue 50000

5 nocache

6* nocycle
SQL> /
Sequence created.
SQL>begin

2 dbms_scheduler.create_job(
3 job_name=>'insert_job',
4 job_type=>'plsql_block',

5 job_action=>'insert into test values(s.nextval,s2.nextval);',
6 start_date=>sysdate,
7 repeat_interval=>'freq=secondly;interval=5',
8 enabled=>false);
9 end;

10 /
PL/SQL procedure successfully completed.
SQL> select * from test;
no rows selected
SQL> exec dbms_scheduler.enable('insert_job');
PL/SQL procedure successfully completed.
SQL>
SQL> select * From test;
EMPNO DEPTNO

7000 10
7000 10

7100 20
SQL> /

EMPNO DEPTNO
---------- ----------
7000 10
7100 20
7200 30
7300 40
SQL> /

EMPNO DEPTNO
---------- ----------

7000 10

7200 30

7300 40

7400 50
SQL> exec dbms_scheduler.disable('insert_job');
PL/SQL procedure successfully completed.
SQL> select * from test;

EMPNO DEPTNO
---------- ----------
7000 10
7100 20

7200 30

7300 40

7400 50
7500 60
7600 70

7700 80
8
rows selected.
SQL> exec dbms_scheduler.drop_job('insert_job');
PL/SQL procedure successfully completed.
SQL> truncate table test;

Table truncated.
SQL> --creating program
SQL>
SQL> begin

2 dbms_scheduler.create_program(

3 program_name=>'insert_prog',
4 program_type=>'plsql_block',
5 program_action=>'insert into test values(s.nextval,s2.nextval);',
6 enabled=>true);
7 end;

8 /
PL/SQL procedure successfully completed.

SQL> begin

2 dbms_scheduler.create_schedule(

3 schedule_name=>'insert_sch',

4 start_date=>sysdate,
5 end_date=>sysdate+1,

6 repeat_interval=>'freq=secondly;interval=5');

7* end;
8 /
PL/SQL procedure successfully completed.
SQL> --creating job and calling program and scheduler in job

SQL> begin

2 dbms_scheduler.create_job(

3 job_name=>'job2',
4 program_name=>'insert_prog',
5 schedule_name=>'insert_sch');
6 end;

7 /
PL/SQL procedure successfully completed.
SQL> exec dbms_scheduler.enable('job2');
PL/SQL procedure successfully completed.
SQL> select * from test;

EMPNO DEPTNO
---------- ----------
7800 90
SQL> /
EMPNO DEPTNO
---------- ----------

7800 90

7900 100
SQL> /

EMPNO DEPTNO
---------- ----------

7800 90

7900 100

8000 110
SQL> exec dbms_scheduler.disable('job2');
PL/SQL procedure successfully completed.