|
| 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