2018年6月6日 星期三
ORACLE 11G 設定帶有參數的 SCHEDULER JOB
---------- 建立一個 SCHEDULER 裏頭的 PROGRAM 先設定變數型態
---------- 以下範例的 PROCEDURE 是需要帶入兩個參數 , 這邊先設定變數型態 一個是 NUMBER 另外一個是 VARCHAR2
BEGIN
SYS.DBMS_SCHEDULER.CREATE_PROGRAM
(
program_name => 'DBA_TN_REPORT_P'
,program_type => 'STORED_PROCEDURE'
,program_action => 'DBA_TN_REPORT'
,number_of_arguments => 2
,enabled => FALSE
,comments => 'DBA_TN_REPORT'
);
SYS.DBMS_SCHEDULER.DEFINE_PROGRAM_ARGUMENT
(
program_name => 'DBA_TN_REPORT_P'
,argument_name => 't_thread_no'
,argument_position => 1
,argument_type => 'NUMBER'
,default_value => ''
);
SYS.DBMS_SCHEDULER.DEFINE_PROGRAM_ARGUMENT
(
program_name => 'DBA_TN_REPORT_P'
,argument_name => 't_over_night'
,argument_position => 2
,argument_type => 'VARCHAR2'
,default_value => ''
);
SYS.DBMS_SCHEDULER.ENABLE
(name => 'DBA_TN_REPORT_P');
END;
/
---------- 建立一個 SCHEDULER 設定排程, 且這邊帶入參數
BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB
(
job_name => 'DBA_TN_REPORT_JOB'
,start_date => TO_TIMESTAMP_TZ('2017/04/14 01:54:00.000000 +08:00','yyyy/mm/dd hh24:mi:ss.ff tzr')
,repeat_interval => 'FREQ=minutely; INTERVAL= 3'
,end_date => NULL
,program_name => 'DBA_TN_REPORT_P'
,comments => 'DBA_TN_REPORT_P'
);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'RESTARTABLE'
,value => FALSE);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'LOGGING_LEVEL'
,value => SYS.DBMS_SCHEDULER.LOGGING_OFF);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE_NULL
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'MAX_FAILURES');
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE_NULL
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'MAX_RUNS');
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'STOP_ON_WINDOW_CLOSE'
,value => FALSE);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'JOB_PRIORITY'
,value => 3);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE_NULL
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'SCHEDULE_LIMIT');
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'DBA_TN_REPORT_JOB'
,attribute => 'AUTO_DROP'
,value => FALSE);
--- 這邊帶入想要的值進去
SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
( job_name => 'DBA_TN_REPORT_JOB'
,argument_name => 't_thread_no'
,argument_value => 1);
SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
( job_name => 'DBA_TN_REPORT_JOB'
,argument_name => 't_over_night'
,argument_value => 's');
END;
/
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言