温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

oracle job的迁移

发布时间:2020-06-24 22:08:19 来源:网络 阅读:1600 作者:freedomzm 栏目:关系型数据库

因为JOB的内容是写死的,如果使用remap导入到别的用户下,其log_user等还是原来的,再加上job的id是固定的,很可能和当前库有冲突,所以建议取出job的ddl。

 

dbms_metadata.get_ddl是不可以的。不行你们试试就知道了。

 

所以我写了个plsql

set serveroutput on size 100000 set termout on set feedback off clear screen spool /opt/soft/bak/make_jobs.sql prompt -- exporting jobs begin << 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;

然后切换过去再删除,同理,建立也必须使用当前用户。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI