数据泵导入,报错:ORA-12899: value too large for column "SCOTT"."TEST112"."JOIN" (actual: 9, maximum: 8)

1.报错:

数据泵执行导入时报错:ORA-12899: value too large for column "SCOTT"."TEST112"."JOIN" (actual: 9, maximum: 8)

2.分析:

由报错,可知,应该是源端表和目标端表字符长度不一致,目标端字符长度最大值无法容纳源端表,所以导入会报错ORA-12899

解决思路:

1)更改目标端字段长度(最简单),改完之后可成功导入

2)通过dblink,目标端CTAS时直接指定字符类型,然后插入目标端表

3)直接在源端CTAS建立中间表,然后用数据泵导出中间表数据,然后把dmp文件传到目标端,目标端执行数据泵导入

3.解决:

最终和研发沟通,研发说目标端表无法更改字符类型,因为分析需要varchar2(8),而源端也无法更改字符类型。

生产环境源端和目标端数据库不在一个网络,而且不允许打通,所以dblink方式无法使用

所以只能通过CTAS构建中间表时转换字符类型,然后用数据泵把中间表导出,再导入目标端即可。

实验环境模拟:

1)建立两张表test111和test112,test111作为源端表,test112作为目标端表

SQL> create table test111(id number(10),join date);

SQL> insert into test111 values(1,sysdate);

1 row created.

SQL> insert into test111 values(2,sysdate-1);

1 row created.

SQL> commit;

SQL> create table test112(id number(10),join varchar2(8));

Table created.

2)首先查看目标端和源端的表结构,和字段类型是否一致,发现源端表test111的join列字符类型为date,而目标端表test112字符类型为varchar2(8)

1)SQL> desc test111;
 Name                       Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                            NUMBER(10)
 JOIN                            DATE

SQL> desc test112;
 Name                       Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                            NUMBER(10)
 JOIN                            VARCHAR2(8)

2)并向test111插入两条数据,最终test111有两条数据,test112表为空

SQL> select id,to_char(join,'yyyymmdd') from test111;

    ID TO_CHAR(JOIN,'YYYYMMDD')
---------- ------------------------
     1 20200313
     2 20200312

SQL> select * from test112;

no rows selected



3)CTAS建立中间表test118,经过数据类型转换使得test111的值插入test118

SQL> create table test118 as select id,to_char(join,'yyyymmdd') join from test111;

Table created.

SQL> select * from test118;

    ID JOIN
---------- ------------------------
     1 20200313
     2 20200312

SQL> desc test118;
 Name                       Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                            NUMBER(10)
 JOIN                            VARCHAR2(8)

4)用数据泵导出test118数据

mkdir -p /home/oracle/expdp

chmod -R 777 /home/oracle/expdp

create directory expdp as '/home/oracle/expdp';

grant all on directory expdp on scott;

expdp scott/tiger directory=expdp  tables=test118 dumpfile=test118%U.dmp logfile=test118.log

5)再次用数据泵导入test112

[oracle@host01 expdp]$ impdp scott/tiger remap_table=test118:test112 dumpfile=test118%U.dmp logfile=test118.log directory=expdp table_exists_action=append

6)结果验证(test111数据成功导入test112,只不过join列显示有点差别,因为字符类型不同)


SQL> select * from test112;

    ID JOIN
---------- ------------------------
     1 20200313
     2 20200312


SQL> select * from test111;

    ID JOIN
---------- ------------------
     1 13-MAR-20
     2 12-MAR-20


猜你喜欢

转载自www.cnblogs.com/gw666/p/12487120.html