Skip to content

Commit 854c550

Browse files
committed
added job
1 parent 3101a0f commit 854c550

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

create_function_toddog.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
prompt create library using libtoddog.so
2-
32
CREATE OR REPLACE LIBRARY libtoddog AS '${ORACLE_HOME}/lib/libtoddog.so';
43
/
5-
prompt create function f_metrictoddog
4+
show err
65

6+
prompt create function f_metrictoddog
77
CREATE OR REPLACE FUNCTION f_metrictoddog (
88
name IN VARCHAR2,
99
metric IN BINARY_INTEGER,

samples/rowcount.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ EXCEPTION
2525
raise_application_error(err_num, err_msg);
2626
END;
2727
/
28-
2928
show err
3029

3130
exit

samples/rowcount_job.sql

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
set serveroutput on
2+
3+
CREATE OR REPLACE PROCEDURE proc_rowcount_toddog AS
4+
name varchar2(50);
5+
result varchar2(10);
6+
cursor c_table is
7+
select TABLE_NAME, NUM_ROWS from all_tables where OWNER = 'HR';
8+
errorinloop EXCEPTION;
9+
err_num NUMBER;
10+
err_msg VARCHAR2(100);
11+
begin
12+
name := 'sample.rowcount';
13+
for t in c_table loop
14+
result := f_gaugetoddog(name,t.num_rows,t.table_name);
15+
IF result != 'done' THEN
16+
RAISE errorinloop;
17+
END IF;
18+
end loop;
19+
EXCEPTION
20+
WHEN errorinloop THEN
21+
raise_application_error(-20101, 'error inside loop on samples/rowcount.sql');
22+
WHEN OTHERS THEN
23+
err_num := SQLCODE;
24+
err_msg := SUBSTR(SQLERRM, 1, 100);
25+
raise_application_error(err_num, err_msg);
26+
END;
27+
/
28+
29+
show err
30+
31+
begin
32+
proc_rowcount_toddog;
33+
end;
34+
/
35+
36+
37+
38+
declare
39+
job_doesnt_exist EXCEPTION;
40+
PRAGMA EXCEPTION_INIT( job_doesnt_exist, -27475 );
41+
begin
42+
dbms_scheduler.drop_job(job_name => 'job_rowcount_toddog');
43+
exception when job_doesnt_exist then
44+
null;
45+
end;
46+
/
47+
show err
48+
49+
BEGIN
50+
DBMS_SCHEDULER.create_job (
51+
job_name => 'job_rowcount_toddog',
52+
job_type => 'PLSQL_BLOCK',
53+
job_action => 'BEGIN proc_rowcount_toddog; END;',
54+
start_date => SYSTIMESTAMP,
55+
repeat_interval => 'FREQ=MINUTELY;INTERVAL=15;',
56+
end_date => NULL,
57+
enabled => TRUE,
58+
comments => 'Job defined entirely by the CREATE JOB procedure.');
59+
END;
60+
/
61+
62+
prompt check if job enabled
63+
SELECT ENABLED as E FROM DBA_SCHEDULER_JOBS where JOB_NAME = UPPER('job_rowcount_toddog');
64+
65+
set lines 110
66+
prompt check last runs
67+
select status, ACTUAL_START_DATE from DBA_SCHEDULER_JOB_RUN_DETAILS
68+
where job_name = UPPER('job_rowcount_toddog')
69+
order by ACTUAL_START_DATE DESC
70+
FETCH FIRST 5 ROWS ONLY
71+
;
72+
73+
74+
exit
75+

0 commit comments

Comments
 (0)