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;

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

相关内容

热门资讯

河南一企业每月给员工父母发“工... 近日,河南一企业每月1日给员工父母发“工资”一事在网上引热议,很多人点赞,更多也是好奇:咋发?发多少...
“90后夫妻同患罕见病瘫痪”引... 近日,一段“90后新婚夫妻同患罕见病瘫痪”的视频在网上流传,引发关注和热议。有网友对夫妻俩的遭遇表示...
北京:每年开放场景空间资源和场... 5月13日,北京市发展改革委、北京市科委、中关村管委会等部门联合发布了《北京市加快推动场景培育和开放...
DAA衡量智能体的时代,云服务... 今年以来,国内外头部云厂商相继上调部分核心产品价格,打破了行业近二十年“只降不升”的惯例。这背后,是...
2026年网络发稿平台权威测评... 引言:数字化浪潮下,网络发稿生态正在经历深刻变革 在信息爆炸的互联网时代,网络空间已成为企业品牌传播...
“小皮球,架脚踢,马兰开花二十... “二八二五六,二八二五七,二八二九三十一……”当短视频里的外国网友惊呼“这是什么暗号”时,有网友笑称...
房子重新装修需要多少钱(房子重... 像新房子装修后的使用寿命大概在15到20年的样子,之后的各种材料都因时间的关系会逐渐老化,看着越来越...
不锈钢橱柜多少一米 具体要看你使用的不锈钢是哪种型号的,因为市面上有很多种型号的不锈钢,当然价钱也有所不同。那么我们普通...
300-300的瓷砖是多少平方 我们在计算平方的时候,都是将长度乘以宽度,所以300×300的瓷砖,这些瓷砖的面积肯定是0.9个平方...
热水器是一直开着省电还是现用现... 一般情况下家用的热水器是现用现烧比较省电,当热水器一直开着时,热水器会一直持续进行烧水工作,这样会比...