当前位置: 首页 > news >正文

Oracle案例:迁移含有LONG字段的表

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。

Oracle案例:迁移含有LONG字段的表

在上周5遇到一个客户truncate了一张800G的表,表中含有LONG字段,异机还原+迁移表,折腾啊,总共还原了2天2夜才还原成功,中途遇到了空间不够等问题。

下面是测试表含有LONG字段的迁移的几种方法。

测试环境是:OS RHEL 4.8 DB:10.2.0.4

建议在带有long字段的表的迁移的时候,使用exp/imp的方式。

1,配置NLS_LANG参数

[oracle10g@rhel4 sql]$ export NLS_LANG='AMERICAN_AMERICA.ZHS16GBK';
[oracle10g@rhel4 sql]$ echo $NLS_LANG
AMERICAN_AMERICA.ZHS16GBK

2,创建测试表

 create table scott.test_long(htz varchar2(20),huangtingzhong long);insert into scott.test_long values('htz1','黄廷忠1');insert into scott.test_long values('htz2','黄廷忠2');insert into scott.test_long values('htz3','黄廷忠3');insert into scott.test_long values('htz4','黄廷忠4');insert into scott.test_long values('htz5','黄廷忠5');insert into scott.test_long values('htz6','黄廷忠6');commit;
www.htz.pw >set lines 200
www.htz.pw >select * from scott.test_long;
HTZ                  HUANGTINGZHONG
-------------------- --------------------------------------------------------------------------------
htz1                 黄廷忠1
htz2                 黄廷忠2
htz3                 黄廷忠3
htz4                 黄廷忠4
htz5                 黄廷忠5
htz6                 黄廷忠6
6 rows selected.

3,使用常规的CTAS方法来迁移报错,MOVE也报错

www.htz.pw >create table scott.test1_long as select * from scott.test_long;
create table scott.test1_long as select * from scott.test_long*
ERROR at line 1:
ORA-00997: illegal use of LONG datatype
www.htz.pw >alter table scott.test_long move;
alter table scott.test_long move
*
ERROR at line 1:
ORA-00997: illegal use of LONG datatype

4,使用expdp的network_link方式

[oracle10g@rhel4 sql]$ impdp scott/oracle directory=exp_test logfile=long.log tables=test2_long remap_schema=scott:htz network_link=expdp_long
Import: Release 10.2.0.4.0 - 64bit Production on Saturday, 18 May, 2013 17:26:46
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** directory=exp_test logfile=long.log tables=test2_long remap_schema=scott:htz network_link=expdp_long 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-31679: Table data object "HTZ"."TEST2_LONG" has long columns, and longs can not be loaded/unloaded using a network link
Job "SCOTT"."SYS_IMPORT_TABLE_01" completed with 1 error(s) at 17:26:50

5,通过COPY的方式

在生产中COPY命令使用时我们需要注意几个方面1,多少条记录后提交一次(copycommit(非0)*arraysize),如果UNDO表空间足够大的时候,我们不需要考虑这个。2,配置一下long的值,默认是80,弄个最大值2000000000在群中的E总,说带有LONG字段的表使用COPY的方式会出问题,但是我不知道会出什么问题。www.htz.pw >show copycommit;
copycommit 0
www.htz.pw >show arraysize
arraysize 15
www.htz.pw >copy         
usage: COPY FROM <db> TO <db> <opt> <table> { (<cols>) } USING <sel><db>   : database string, e.g., hr/your_password@d:chicago-mktg<opt>  : ONE of the keywords: APPEND, CREATE, INSERT or REPLACE<table>: name of the destination table<cols> : a comma-separated list of destination column aliases<sel>  : any valid SQL SELECT statement
A missing FROM or TO clause uses the current SQL*Plus connection.
www.htz.pw >copy from scott/oracle@orcl10g create scott.test1_long using select * from scott.test_long;
Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 80. (long is 80)
Table SCOTT.TEST1_LONG created.6 rows selected from scott@orcl10g.6 rows inserted into SCOTT.TEST1_LONG.6 rows committed into SCOTT.TEST1_LONG at DEFAULT HOST connection.
通过COPY迁移出来的记录是正常的,也没有出现乱码现象。www.htz.pw >select * from scott.test1_long;HTZ                  HUANGTINGZHONG
-------------------- --------------------------------------------------------------------------------
htz1                 黄廷忠1
htz2                 黄廷忠2
htz3                 黄廷忠3
htz4                 黄廷忠4
htz5                 黄廷忠5
htz6                 黄廷忠6

6,通过expdp方式来迁移

在使用expdp方式来迁移的时候,MACLEAN中提到下面这句话“
例如10g中推出的数据泵功能data pump expdp/impdp,在2个字符集完全一致(ZHS16GBK AL16UTF16)的数据库间导入、导出LONG  字段也可能存在乱码,这个现象在10g中比较常见。”由于expdp/impdp导long会出现乱码,建议使用exp/imp工具来导包含有long字段的表,在他的测试中11G以上乱码现象得到修复。www.htz.pw >create directory dump_test as '/tmp';
Directory created.
www.htz.pw >grant write,read on directory dump_test to scott;
Grant succeeded.
www.htz.pw >!expdp scott/oracle directory=dump_test dumpfile=test1_long_expdp.dmp logfile=test1_long_expdp.log tables=test_long;
Export: Release 10.2.0.4.0 - 64bit Production on Friday, 24 May, 2013 10:11:09
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=dump_test dumpfile=test1_long_expdp.dmp logfile=test1_long_expdp.log tables=test_long 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."TEST_LONG"                         5.335 KB       6 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:/tmp/test1_long_expdp.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 10:11:12
导出成功,没有报任何的错误
drop掉相当的表
www.htz.pw >drop table scott.test_long purge;
Table dropped.
导入数据
www.htz.pw >!impdp scott/oracle directory=dump_test dumpfile=test1_long_expdp.dmp logfile=test1_long_expdp.log tables=test_long;
Import: Release 10.2.0.4.0 - 64bit Production on Friday, 24 May, 2013 10:12:44
Copyright (c) 2003, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/******** directory=dump_test dumpfile=test1_long_expdp.dmp logfile=test1_long_expdp.log tables=test_long 
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."TEST_LONG"                         5.335 KB       6 rows
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 10:12:46
查看导入的数据,一切正常没有出现乱码的现象www.htz.pw >select * from scott.test_long;
HTZ                  HUANGTINGZHONG
-------------------- --------------------------------------------------------------------------------
htz1                 黄廷忠1
htz2                 黄廷忠2
htz3                 黄廷忠3
htz4                 黄廷忠4
htz5                 黄廷忠5
htz6                 黄廷忠6
6 rows selected.

7,使用exp的方式来导数据

     在使用exp方式来导数据库的使用,建议配置direct=y与recordlength两个参数来提高性能,在imp导入的时候,如果在UNDO表空间不够的情况下,建议加上commit=y,在有long字段的imp时,每插入一条记录都会commit一次,而是达到buffer值时才commit,这点需要注意,commit次数的增加会导致性能的下降。
www.htz.pw >!exp scott/oracle file=/tmp/test1_long_exp.dmp log=test1_long_exp.log tables=test_long
Export: Release 10.2.0.4.0 - Production on Fri May 24 10:11:42 2013
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table                      TEST_LONG          6 rows exported
Export terminated successfully without warnings.
www.htz.pw >drop table scott.test_long purge;
Table dropped.www.htz.pw >!imp scott/oracle file=/tmp/test1_long_exp.dmp log=test1_long_exp.log tables=test_long
Import: Release 10.2.0.4.0 - Production on Fri May 24 10:13:38 2013
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V10.02.01 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing SCOTT's objects into SCOTT
. importing SCOTT's objects into SCOTT
. . importing table                    "TEST_LONG"          6 rows imported
Import terminated successfully without warnings.www.htz.pw >select * from scott.test_long;HTZ                  HUANGTINGZHONG
-------------------- --------------------------------------------------------------------------------
htz1                 黄廷忠1
htz2                 黄廷忠2
htz3                 黄廷忠3
htz4                 黄廷忠4
htz5                 黄廷忠5
htz6                 黄廷忠66 rows selected.

一切正常。

------------------作者介绍-----------------------
姓名:黄廷忠
个人博客: (http://www.htz.pw)
CSDN地址: (https://blog.csdn.net/wwwhtzpw)
博客园地址: (https://www.cnblogs.com/www-htz-pw)

http://www.jsqmd.com/news/44744/

相关文章:

  • AOI检测设备厂家推荐:聚焦高精度表面检测技术应用
  • 微波烘干设备安全性能:核心技术与应用解析
  • 邻接链表实战反思:从一次超时错误,看透数据结构的“映射本质”
  • AOI光学检测设备厂家哪家好?行业实力企业推荐
  • 免费网络研讨会 | 功能安全十步走
  • AOI检测设备定制厂家实力解析:工业质量监控技术方案对比
  • 能提高免疫力的灵芝品牌哪家好?这份榜单值得关注
  • AI元人文:“协议”二字的由来
  • 提升免疫力的靠谱保健品推荐:多款优质产品深度解析
  • 有助于增强免疫力的保健品有哪些
  • 哪些保健品能提高免疫力?常见品类及成分解析
  • 展厅装修公司推荐:专业服务与行业标杆企业解析
  • 云边协同发力!异地水厂监控+AI分析,不折腾设备还能省成本的解法!
  • 展厅设计公司推荐:国内优质服务企业盘点
  • 展厅设计公司有哪些?国内知名机构推荐
  • 解决4K屏下VMware虚拟机中界面太小问题
  • 国内AI公司估值排行:行业格局与核心企业实力观察
  • linux exec find
  • linux event
  • linux eth1 eth0
  • 上海AI创业公司排行榜:2025年创新力量与技术突破解析
  • 深入解析:【UE4 / UE5】 一键打包 Dedicated Server 专用服务器(不需要C++ 版)
  • 2025 年 11 月活动隔断厂家推荐排行榜,移动隔断,折叠隔断,推拉隔断,电动隔断,玻璃隔断,酒店隔断,办公隔断,会议室隔断,展板隔断公司推荐
  • 2025年车间降温设备供货厂家权威推荐榜单:冷冻柜/冷风机/滑雪场制冷设备源头厂家精选
  • 2025 年 11 月隔墙厂家推荐排行榜,移动隔墙,推拉隔墙,活动隔墙,办公隔墙,玻璃隔墙,隔音隔墙,吸音板隔墙公司推荐
  • [题解]P10282 [USACO24OPEN] Smaller Averages G
  • 为什么求方差和标准差至少需要两个数据点?
  • JavaWeb07-SpringBoot相关配置
  • 易基因:J Hazard Mater(IF11.3):安徽农大任大龙团队ChIP-seq等揭示微塑料暴露介导中性粒细胞免疫毒性的调控机制
  • 习题解析之:字符串长度