step-1.
---create procedure what you
want to do ---------------
CREATE OR REPLACE PROCEDURE rak.dpr_insert is
begin
insert into TEMP (col1,col2,col3,col4,col5)
values('test','1','test','2','rakib');
end;
step-2.
-----create job--------------
DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
(
job => X
,what => 'dpr_insert;'
,next_date
=> to_date('03/07/2012 13:35:31','dd/mm/yyyy hh24:mi:ss')
,interval => 'sysdate
+ 2 / (24 * 60)'
,no_parse => FALSE
);
SYS.DBMS_OUTPUT.PUT_LINE('Job
Number is: '
|| to_char(x));
COMMIT;
END;
step-3 ----------view create-------------
GRANT SELECT on dba_jobs to rak;(SYS User)
CREATE OR REPLACE FORCE VIEW RAK.vw_jobinfo (job,
job_id,
description,
status,
broken,
what,
INTERVAL,
next_date,
next_sec,
failures
)
AS
SELECT job,
DECODE (UPPER (what),
'DPR_INSERT;', '01'
) job_id,
DECODE (UPPER (what),
'DPR_INSERT;',
'Insert data Into Temp'
) description,
DECODE (broken, 'N', 'Active', 'Inactive') status, broken, what,
INTERVAL, next_date, next_sec, failures
FROM
SYS.dba_jobs
WHERE schema_user = 'RAK';
GRANT SELECT on dba_jobs_running to rak;
CREATE OR REPLACE FORCE VIEW rak.vw_runningjob (SID,
job,
description,
what,
this_date,
this_sec
)
AS
SELECT r.SID, r.job,
DECODE (UPPER (what),
'dpr_insert;', 'Insert Data Into Temp'
) description,
what, r.this_date, r.this_sec
FROM
SYS.dba_jobs_running r, SYS.dba_jobs j
WHERE r.job = j.job AND j.schema_user = 'RAK';
Step-4.
--------------------------------------
CREATE OR REPLACE Procedure RAK.DPR_JobManagement(pJob Number, -- Job No
pBroken Varchar2, -- Y for Broken, N for Not Broken
pError Out Varchar2
)
Is
vCount
Number;
vBroken
Char(1);
Begin
Select Broken Into vBroken
From
vw_jobinfo
Where JOB = pJob;
If
vBroken <> pBroken Then
Select Count(SID) Into vCount
From
vw_runningjob
Where JOB = pJob;
If
vCount = 0 Then
If
pBroken = 'N' Then
-- For Broken state to Un Broken state
dbms_job.broken(JOB=>pJob, NEXT_DATE=>SYSDATE, broken=>FALSE);
Else
-- For Un Broken state to Broken state
dbms_job.broken(pJob, TRUE);
End
If;
Commit;
Else
pError := 'Procedure is running. Please
do this job in next time.';
End
If;
End
If;
Exception
When
Others Then
pError := SqlErrm;
End;
/