標籤:job dba_jobs dbms_job
因為JOB的內容是寫死的,如果使用remap匯入到別的使用者下,其log_user等還是原來的,再加上job的id是固定的,很可能和當前庫有衝突,所以建議取出job的ddl。
dbms_metadata.get_ddl是不可以的。不行你們試試就知道了。
所以我寫了個plsql
set serveroutput on size 100000set termout onset feedback offclear screenspool /opt/soft/bak/make_jobs.sqlprompt -- exporting jobsbegin<< export_jobs >>declare subtype job_type is user_jobs.JOB%type ; subtype max_text_type is varchar2( 8191 char ) ; type job_tab_type is table of job_type index by pls_integer ; type sql_tab_type is table of max_text_type index by pls_integer ; job_tab job_tab_type ; sql_tab sql_tab_type ; job pls_integer ; what pls_integer ; next_date pls_integer ; interval pls_integer ; no_parse pls_integer ; procedure get_jobs is begin select j.JOB bulk collect into job_tab from user_jobs j order by 1 ; end get_jobs ; procedure format( x pls_integer ) is sqlx max_text_type := null ; begin sqlx := ‘begin‘ || chr(10); job := instr( sql_tab(x), ‘(job=>‘ ) ; sqlx := sqlx || substr( sql_tab(x), 1, job-1 ) || chr(10) ; what := instr( sql_tab(x),‘,what=>‘ ) ; sqlx := sqlx || substr( sql_tab(x), job, what-job ) || chr(10) ; next_date := instr( sql_tab(x),‘,next_date=>‘ ) ; sqlx := sqlx || substr( sql_tab(x), what, next_date-what ) || chr(10) ; interval := instr( sql_tab(x),‘,interval=>‘ ) ; -- sqlx := sqlx || substr( sql_tab(x), next_date, interval-next_date ) || chr(10) ; sqlx := sqlx || q‘|,next_date=>‘01-JAN-3000‘|‘ || chr(10) ; no_parse := instr( sql_tab(x),‘,no_parse=>‘ ) ; sqlx := sqlx || substr( sql_tab(x), interval, no_parse-interval ) || chr(10) ; sqlx := sqlx || ‘,no_parse=>TRUE‘ || chr(10) || ‘);‘ || chr(10) ; sqlx := sqlx || ‘commit;‘ || chr(10) || chr(10) ; sqlx := sqlx || ‘end;‘ || chr(10) || ‘/‘ || chr(10) ; sql_tab(x) := sqlx; end format ; begin get_jobs; if job_tab.count > 0 then for i in 1 .. job_tab.count loop sql_tab(i) := ‘ ‘; sys.dbms_job.user_export ( job => job_tab(i) , mycall => sql_tab(i) ); format(i) ; dbms_output.put_line( sql_tab(i) ) ; end loop ; else dbms_output.put_line( ‘-- Nothing to do.‘ ) ; end if ;end export_jobs;end;/spool off
然後呢,用這個得到輸出重建job。如果你遇到
ORA-00001: unique constraint (SYS.I_JOB_JOB) violated
就說明job列重複了,這時候你有兩種方法,一個是重設job,改個沒人用的。
另一種就是刪了現在的job重建。
刪除文法是
exec dbms_job.remove(25);
如果刪除時遇到如下:
ORA-23421: job number 387 is not a job in the job queue
很有可能是因為你的使用者不是job的owner。
select job,log_user,priv_user,schema from dba_jobs where job=25;
然後切換過去再刪除,同理,建立也必須使用目前使用者。
本文出自 “機動戰士高達Oracle” 部落格,請務必保留此出處http://gundam.blog.51cto.com/1845787/1613250
oracle job的遷移