expdp及impdp中的exclude及include参数

来源:互联网 发布:筒灯选择 知乎 编辑:程序博客网 时间:2024/05/18 15:56

在oracle的expdp 及imdpd命令中,exclude及include参数还是有一些要注意的地方,特别是涉及选择性条件时。

一、通用

1、exclude及include参数不能同时使用,这两个是相互排斥的。

2、在parfile参数文件中,可以同时用多个exclude参数,但只能用一个include参数

3、include、exclude参数是默认就是针对名称操作的:如表名、视图名、过程名、包名等,所以设计条件时,可以从查询语句中先取得这些名称。

4、include、exclude参数中,在escape语句中,不能用\作为转义符

   (1)、include=table:"like 'SEC_%'" 
     结果:SECAAAROLE、SEC_ROLE、SEC_OPERATION三个表,说明,_依旧表示一个占位符的作用

   (2)、include=table:"like 'SEC\_%'"
       不能导出SECAAAROLE、SEC_ROLE、SEC_OPERATION三个表,说明在''中,\并不表示转义符

   (3)、include=table:"like 'SEC\_%'escape'\'"  这样会报错:
       ORA-39001: invalid argument value
       ORA-39071: Value for INCLUDE is badly formed.
       ORA-01425: escape character must be character string of length 1
    (4)、改成这样  include=table:"like 'SEC#_%'escape'#'"
         可以正确导出SEC_ROLE、SEC_OPERATION二个表,但不能导出SECAAAROLE这个表。结论:在include、exclude参数中,在escape语句中,不能用\作为转义符!!,可以选用选用其他特殊字符作为转义符。如果确实要用\,也要可以用ascii码代替:include=table:"like 'SEC\_%'escape chr(92)"

 

二、exclude参数用法

a、exclude参数在parfile文件中可以有多个,还有多种写法。

[oracle@test189 temp2]$ vi zzw-expscript_impclude.par 
DIRECTORY=ZZW_EXPDPDIR
DUMPFILE=bdctemp1.dmp
exclude=table:"like 'BDC%'" , table:"like 'USPC%'",table:"like 'AUDIT%'"
exclude=table:"like 'SMS#_%'escape'#'"
exclude=table:"in (select table_name from user_tables  where regexp_like(table_name,'^MENU.*')
or regexp_like(table_name,'^SEC_.*_.*$'))"
LOGFILE=bdctemp1.log

b、支持换行,比如,上面的语句,在parfile文件中如下换行也是可以的

[oracle@test189 temp2]$ vi zzw-expscript_impclude.par 
DIRECTORY=ZZW_EXPDPDIR
DUMPFILE=bdctemp1.dmp
EXCLUDE=STATISTICS
exclude=view,table:"like 'BDC%'" ,
table:"like 'USPC%'",
table:"like 'AUDIT%'"
exclude=table:"like 'SMS#_%'escape'#'"
exclude=table:"in (select table_name from user_tables  where regexp_like(table_name,'^MENU.*') 
or regexp_like(table_name,'^SEC_.*_.*$'))"
LOGFILE=bdctemp1.log

 

    ps:采用这种exclude=table:"in (select table_name from user_tables)"方法导出时,我环境中会出现 ORA-07445: exception encountered: core dump     [kokemisz()+34] [SIGSEGV] [ADDR:0x18] [PC:0x143F5B6] [Address not mapped to object] []  这样的错误,在parfile文件中加入 EXCLUDE=STATISTICS条件问题就解决了。

三、include参数用法

a、不允许的写法

    include=table:"='BOSS'" or table:"='SEC_ROLE'"

    include=table:"='BOSS'" , table:"='SEC_ROLE'"

b、允许的写法
     include=table:"='BOSS'"

    include=table:"in('BOSS','SEC_ROLE')"

    include=table:"in(select table_name from user_tables  where table_name in('BOSS','SEC_ROLE'))"

    include=table:"in(select table_name from user_tables  where regexp_like(table_name,'^BDC_.{4}_.*$'))"   #注意,_在like中表示占位符,在regexp_like不表示占位符。 

     include=table:"in(select table_name from user_tables  where regexp_like(table_name,'^BDC_.{8}_.*$') or regexp_like(table_name,'^ATTACHMENT_.{4}') or  table_name like 'QRTZ#_%'escape'#')"

c、网上有人提供的好方法(http://i.ruby.blog.163.com/blog/static/2479341720137129551334/?suggestedreading&wumii)

   导出某些无规律的表,有很多,也许需要动态维护
    建立表exp_table
    create table exp_table (table_name varchar2(100);
    然后将需要导出的表名插入exp_table中。
    insert into exp_table values(‘A’);
    insert into exp_table values(‘B’);
    insert into exp_table values(‘PUB_GOODS’);
    insert into exp_table values(‘PUB_GOODS_UNIT’);

    最后导出的的时候:
    parfile
    userid=user/passwd
    directory=expdir
    dumpfile=testfile.dmp
    include=table:" in (select table_name from exp_table ) "
    这样就可以导出exp_table中所包含的所有表了。更神奇的是,可以在exp_table里面将自己也插入进去,然后把exp_table也导出哦

 

 d、这样的写法是错误的,因为包含两个include语句

    DIRECTORY=ZZW_EXPDPDIR
    DUMPFILE=bdctemp1.dmp
    include=table:"='BOSS'"
    include=table:"='SIMS'"