oracle jobs 匯出為執行指令碼

2021-04-14 00:21:32 字數 2805 閱讀 6656

/*oracle jobs 匯出為執行指令碼

就是把user_jobs或dba_jobs,導成dbms_job.submit可以插入job的格式

其中user_jobs是當前使用者的job,dba_jobs則是全部

下面只是隨便整理了下,可以按照個人需要修改

設定  file_dir  file_name 引數

匯出檔案內容如最後附所視

侷限性 要設定utl_file_dir(alter system set utl_file_dir=) ,file_dir要包括在

檔案生成在服務端

其實可以封裝成過程,或把結果存入臨時表,或dbms_output.put_line

edit by inreyou 14:41 2007-11-16

*/declare

f         utl_file.file_type;

jobn      integer;

s         varchar2(4000);

file_dir  varchar(100);--目錄

file_name varchar(100);--檔名

begin

file_dir  := 'd:/temp';

file_name := 'utl_file1.sql';

f := utl_file.fopen(file_dir, file_name, 'w');

s := 'declare' || chr(13) || chr(10) || ' jobno number;' || chr(13) ||

chr(10) || 'snd varchar2(20);' || chr(13) || chr(10) || 'begin';

utl_file.put_line(f, s);

--if export all jobs change user_jobs to dba_jobs

for js in (select job, log_user, next_date, broken, interval, what

from user_jobs) loop

--dbms_job.user_export(y,s) 這種格式匯出作業號插入不好處理

s := 'execute immediate ''select to_char(' || js.interval ||

',''||chr(39)

||''yyyy-mm-dd hh24:mi:ss''||chr(39)||'') from dual'' into snd;';

s := s || chr(13) || chr(10) || 'dbms_job.submit(jobno, ' || chr(39) ||

js.what || chr(39) || ',to_date(snd,' || chr(39) ||

'yyyy-mm-dd hh24:mi:ss' || chr(39) || ')' || ',' || chr(39) ||

js.interval || chr(39) || ');' || chr(13) || chr(10);

utl_file.put_line(f, s);

--s:='dbms_job.run(jobno);';

--utl_file.put_line(f,s);

end loop;

s := 'commit;' || chr(13) || chr(10) || 'end;';

utl_file.put_line(f, s);

utl_file.fclose(f);

end;/*附

declare

jobno number;

snd varchar2(20);

begin

execute immediate 'select to_char(trunc(sysdate) + 97 / 96,'||chr(39)

||'yyyy-mm-dd hh24:mi:ss'||chr(39)||') from dual' into snd;

dbms_job.submit(jobno, 'tk_hand.tksp_pre_hand_input;tk_hand.tksp_pre_hand_finance;tk_hand.tksp_acc_hand_in_acc;',to_date(snd,'yyyy-mm-dd hh24:mi:ss'),'trunc(sysdate) + 97 / 96');

execute immediate 'select to_char(trunc(sysdate) + 97 / 96,'||chr(39)

||'yyyy-mm-dd hh24:mi:ss'||chr(39)||') from dual' into snd;

dbms_job.submit(jobno, 'begin null;end;',to_date(snd,'yyyy-mm-dd hh24:mi:ss'),'trunc(sysdate) + 97 / 96');

execute immediate 'select to_char(trunc(sysdate) + 97 / 96,'||chr(39)

||'yyyy-mm-dd hh24:mi:ss'||chr(39)||') from dual' into snd;

dbms_job.submit(jobno, 'tk_hand.tksp_pre_hand_input;tk_hand.tksp_pre_hand_finance;tk_hand.tksp_acc_hand_in_acc;',to_date(snd,'yyyy-mm-dd hh24:mi:ss'),'trunc(sysdate) + 97 / 96');

commit;

end;

*/

C NPIO匯出 動態匯出為Excel

using npoi.hssf.usermodel using npoi.ss.usermodel using system using system.collections.generic using system.data using system.io using system.linq us...

Repeater匯出為excel格式

資料繫結到repeater1 下面是將repeater1的內容匯出的示例 system.io.stringwriter sw new system.io.stringwriter system.web.ui.htmltextwriter hw new system.web.ui.htmltextwr...

Repeater 匯出為excel格式

stringwriter sw new stringwriter htmltextwriter hw new htmltextwriter sw this.rptsaleorder.rendercontrol hw response.clear response.charset rptsaleord...