1. 定時
begin
sys.dbms_scheduler.create_job(job_name => 'job_pro_his_delete_cp',
job_type => 'stored_procedure',
job_action => 'pro_his_delete_cp',
start_date => sysdate,
repeat_interval => 'freq=daily;byhour=1;byminute=0;bysecond=0',
end_date => to_date(null),
enabled => true,
auto_drop => false,
comments => '歷史經驗刪除by stationcode,每天1點');
end;
2. -----儲存過程
-- drop procedure if exists pro_his_delete;/
create or replace procedure pro_his_delete_cp as
v_delete_his_count varchar2(10); --刪除歷史經驗條數
v_delete_seg_count varchar2(10); --刪除分詞歷史經驗條數
v_stationcode varchar2(10);
v_histablename varchar2(50); --表名
v_segtablename varchar2(50); --表名
v_his_cnt_sql varchar2(500);
v_his_del_sql varchar2(500);
v_seg_cnt_sql varchar2(500);
v_seg_del_sql varchar2(500);
v_pro_udt_sql varchar2(500);
begin
---迴圈
for his_delete in (select t.stationcode,t.histablename,t.segtablename
from gisdata.t_pro_his_delete t
where t.isdelete = 'n'
loop
v_stationcode := his_delete.stationcode;
v_histablename := his_delete.histablename;
v_segtablename := his_delete.segtablename;
v_his_cnt_sql :=' select count(*) from ' || v_histablename|| ' where stationcode = ''' || v_stationcode || '''';
execute immediate v_his_cnt_sql into v_delete_his_count;
dbms_output.put_line(v_delete_his_count);
v_his_del_sql := 'delete from ' || v_histablename || ' where stationcode = ''' || v_stationcode ||'''';
dbms_output.put_line(v_his_del_sql);
execute immediate v_his_del_sql;
v_seg_cnt_sql :=' select count(*) from ' || v_segtablename|| ' where bizcode = ''' || v_stationcode || '''';
execute immediate v_seg_cnt_sql into v_delete_seg_count;
dbms_output.put_line(v_delete_seg_count);
v_seg_del_sql := 'delete from ' || v_segtablename || ' where bizcode = ''' || v_stationcode ||'''';
dbms_output.put_line(v_seg_del_sql);
execute immediate v_seg_del_sql;
-- v_pro_udt_sql := 'update t_pro_his_delete t set t.modifytime = sysdate, t.isdelete = ''y'', t.deletehiscount = '''
-- || v_delete_his_count || ''', t.deletesegcount = ''' || v_delete_seg_count ||''' where t.stationcode = '''
-- || v_stationcode ''' and t.isdelete = ''n''';
v_pro_udt_sql := 'update t_pro_his_delete t set t.modifytime = sysdate, t.isdelete = ''y'', t.deletehiscount = '''
|| v_delete_his_count || ''', t.deletesegcount = ''' || v_delete_seg_count ||''' where t.isdelete = ''n'' and t.stationcode = '''
|| v_stationcode || '''';
dbms_output.put_line(v_pro_udt_sql);
execute immediate v_pro_udt_sql;
commit;
end loop;
--異常處理
exception
when others then
dbms_output.put_line(sqlcode || '::'||substr(sqlerrm, 1, 200));
rollback;
end;
/3.呼叫儲存過程
-- 執行
begin
pro_his_delete_cp();
end;
-- 或
call pro_his_delete_cp();
4.手動 呼叫job,不需等定時
begin
-- call the procedure
sys.dbms_scheduler.run_job(job_name => 'job_pro_his_delete_cp',
use_current_session => 'false');
end;
oracle動態呼叫 動態呼叫儲存過程
關鍵字 execute immediate sqlname using in 1 in 2 out c sql create or replace procedure p test a in varchar2,b in varchar2,c out varchar2 2 is 3 begin 4 c...
delphi動態呼叫oracle儲存過程
function fun logincheck var puserinfo tremployee var errormessage string flag string integer varadostoredproctemp tadostoredproc begin adostoredprocte...
oracle 儲存過程 呼叫動態sql
開始時間拼接 00 00 00 v sql select decode length v end 10,concat v end 00 00 00 v end from dual execute immediate v sql 編譯成功,但是儲存過程呼叫失敗。在oracl資料庫中,ddl表示資料庫定...