oracle job的迁移
admin
2023-05-11 02:21:07
0

因为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;

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

相关内容

热门资讯

以军士兵集体丢掉武器抗命,大喊... 据凤凰卫视报道,以色列国防军一军事基地7月30日发生士兵抗命事件,约120名士兵抗议指挥官做法,将武...
蒋成华任商务部副部长 国务院任免国家工作人员。任命蒋成华为商务部副部长。免去蒋成华的商务部国际贸易谈判副代表职务。
伊朗驻华大使:在军事威胁下,不... 新华社北京7月31日电(记者刁慧琳) 伊朗驻华大使法兹里7月28日表示,伊美回到谈判桌的前提是美国必...
伊朗革命卫队在霍尔木兹海峡击中... 当地时间31日,伊朗伊斯兰革命卫队发布声明称,革命卫队海军当天在霍尔木兹海峡击中并扣留了两艘违反禁令...
美媒:特朗普,遇到了一个更强硬... 据《纽约时报》7月29日报道,就在特朗普总统看似放弃战事升级计划几天后,美国再次与伊朗交火。上周末,...
女子做气管镜时不幸身亡,丈夫称... 7月29日,西安刘先生反映妻子在当地医院做支气管镜检查时死亡,看监控时发现医生疑有违规操作。刘先生表...
全网“帮卖西瓜”,然后呢? 近日,河南部分地区西瓜滞销的消息在网上热度很高。很多地方也伸出援手:有景区收购千斤西瓜、免费赠予游客...
美媒:乌克兰袭击伊朗船只,险引... 据《纽约时报》7月28日报道,据伊朗和西方官员称,伊朗曾考虑攻击乌克兰的一个港口,以报复乌克兰对一艘...
20年里,他只画美女,用东方风... 迈进KIM在上海的工作室,迎面是一整墙的美女们。她们像是刚从一场时髦的沙龙里退场,或倚或立,眉宇间是...
Google在港推出AI代理G... 观点网讯:7月29日,Google在香港推出AI代理Gemini Spark,该代理可全天候在后台运...