Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2885306
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: Oracle

2012-08-29 16:32:11

标题比较长,说明一下情况,源库是个informix数据库,目标库是个ORACLE数据库,
利用透明网关将informix数据库的表结构复制到ORACLE数据库中,发现CHAR和VARCHAR2类型的列长度
增大为原来的3倍。
 
如下所示:
 
这是表test在informix中的表结构:

点击(此处)折叠或打开

  1. validno VARCHAR 30
  2. comcode CHAR 4
  3. ownername VARCHAR 60
  4. ownertype CHAR 1
  5. identifytype CHAR 2
  6. identifynumber CHAR 20
  7. ***code CHAR 1
  8. postaddress VARCHAR 120
  9. postcode CHAR 6
  10. phonenumber VARCHAR 32
  11. companytype CHAR 3
在ORACLE中通过CTAS方式创建后的表结构如下:

点击(此处)折叠或打开

  1. SQL> select * from v$version;

  2. BANNER
  3. --------------------------------------------------------------------------------

  4. Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
  5. PL/SQL Release 10.2.0.5.0 - Production
  6. CORE 10.2.0.5.0 Production
  7. TNS for Linux: Version 10.2.0.5.0 - Production
  8. NLSRTL Version 10.2.0.5.0 - Production

  9. SQL> create table huateng
  10.   2 as
  11.   3 select * from "test"@dg4ifmx where 1=0;

  12. Table created.

  13. SQL> desc huateng
  14.  Name Null? Type
  15.  ----------------------------------------- -------- ----------------------------

  16.  validno NOT NULL VARCHAR2(90)
  17.  comcode NOT NULL CHAR(12)
  18.  ownername NOT NULL VARCHAR2(180)
  19.  ownertype NOT NULL CHAR(3)
  20.  identifytype NOT NULL CHAR(6)
  21.  identifynumber NOT NULL CHAR(60)
  22.  ***code CHAR(3)
  23.  postaddress VARCHAR2(360)
  24.  postcode CHAR(18)
  25.  phonenumber VARCHAR2(96)
  26.  companytype CHAR(9)
可以看到列的长度都被无缘无故的增大了3倍。
 
查询了MOS,ORACLE在DOC [ID 374744.1] 描述了这个问题:
 

In certain cases, the the length of Oracle CHAR and VARCHAR columns might be different from the original DB2 columns.
This is due to character set differences that require more (or fewer) bytes in the Oracle representation
than in the original DB2 representation.
In the most common case, the Oracle character set Unicode AL32UTF8 uses 1, 2 or 3 bytes to represent one character. If the DB2 column is single-byte character set and defined as CHAR(10), it shows up through the gateway as CHAR(30). This is required because each single byte character (which only takes 1 byte) may require 1, 2 or 3 bytes to represent the character in Unicode AL32UTF8.
Mainly affected are CHARACTER (CHAR) columns as in Oracle the maximum length of a CHAR column is 2000 and those CHAR columns are padded with spaces.
Root cause is the NLS_LENGTH_SEMANTICS used by the gateway is byte oriented.

ORACLE给出了以下解决方法:

设置透明网关参数HS_KEEP_REMOTE_COLUMN_SIZE
 
11.2.0.1 设置为ALL
 
HS_KEEP_REMOTE_COLUMN_SIZE=ALL
 
11.2.0.2 设置为LOCAL
 
HS_KEEP_REMOTE_COLUMN_SIZE=LOCAL
 
 
我的透明网关版本是11.2.0.1,在透明网关初始化参数中增加参数HS_KEEP_REMOTE_COLUMN_SIZE=ALL:

点击(此处)折叠或打开

  1. [gateway@dbserver admin]$ cat initdg4ifmx.ora
  2. # This is a customized agent init file that contains the HS parameters
  3. # that are needed for the Database Gateway for Informix

  4. #
  5. # HS init parameters
  6. #
  7. HS_FDS_CONNECT_INFO=20.1.32.104:50001/nm_1500_cb_ids/dg4ifmx
  8. HS_FDS_RECOVERY_ACCOUNT=RECOVER
  9. HS_FDS_RECOVERY_PWD=RECOVER
  10. HS_FDS_TRACE_LEVEL=OFF
  11. HS_LANGUAGE=AL32UTF8
  12. HS_RPC_FETCH_SIZE=200000
  13. HS_FDS_FETCH_ROWS=500
  14. HS_NLS_LENGTH_SEMANTICS=CHAR
  15. HS_KEEP_REMOTE_COLUMN_SIZE=ALL
  16. #HS_FDS_TRACE_FILE_NAME =dg4ifmx_trace.trc

重新启动监听器。


 

点击(此处)折叠或打开

  1. [oracle@dbserver admin]$ lsnrctl start

  2. LSNRCTL for Linux: Version 10.2.0.5.0 - Production on 29-AUG-2012 16:28:41

  3. Copyright (c) 1991, 2010, Oracle. All rights reserved.

  4. Starting /u01/app/oracle/product/db10gr2/db_1/bin/tnslsnr: please wait...

  5. TNSLSNR for Linux: Version 10.2.0.5.0 - Production
  6. System parameter file is /u01/app/oracle/product/db10gr2/db_1/network/admin/listener.ora
  7. Log messages written to /u01/app/oracle/product/db10gr2/db_1/network/log/listener.log
  8. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbserver)(PORT=1521)))
  9. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))

  10. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbserver)(PORT=1521)))
  11. STATUS of the LISTENER
  12. ------------------------

  13. Alias LISTENER
  14. Version TNSLSNR for Linux: Version 10.2.0.5.0 - Production
  15. Start Date 29-AUG-2012 16:28:41
  16. Uptime 0 days 0 hr. 0 min. 0 sec
  17. Trace Level off
  18. Security ON: Local OS Authentication
  19. SNMP OFF
  20. Listener Parameter File /u01/app/oracle/product/db10gr2/db_1/network/admin/listener.ora
  21. Listener Log File /u01/app/oracle/product/db10gr2/db_1/network/log/listener.log
  22. Listening Endpoints Summary...
  23.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbserver)(PORT=1521)))
  24.   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
  25. Services Summary...
  26. Service "PL***tProc" has 1 instance(s).
  27.   Instance "PL***tProc", status UNKNOWN, has 1 handler(s) for this service...
  28. Service "carlpdb" has 1 instance(s).
  29.   Instance "carlpdb", status UNKNOWN, has 1 handler(s) for this service...
  30. Service "dg4ifmx" has 1 instance(s).
  31.   Instance "dg4ifmx", status UNKNOWN, has 1 handler(s) for this service...
  32. Service "piccdb" has 1 instance(s).
  33.   Instance "piccdb", status UNKNOWN, has 1 handler(s) for this service...
  34. The command completed successfully

再次创建表问题解决。


 

点击(此处)折叠或打开

  1. SQL> desc huateng
  2.  Name Null? Type
  3.  ----------------------------------------- -------- ----------------------------

  4.  validno NOT NULL VARCHAR2(90)
  5.  comcode NOT NULL CHAR(12)
  6.  ownername NOT NULL VARCHAR2(180)
  7.  ownertype NOT NULL CHAR(3)
  8.  identifytype NOT NULL CHAR(6)
  9.  identifynumber NOT NULL CHAR(60)
  10.  ***code CHAR(3)
  11.  postaddress VARCHAR2(360)
  12.  postcode CHAR(18)
  13.  phonenumber VARCHAR2(96)
  14.  companytype CHAR(9)

  15. SQL> create table huateng1
  16.   2 as
  17.   3 select * from "test"@dg4ifmx where 1=0;

  18. Table created.

  19. SQL> desc huateng1
  20.  Name Null? Type
  21.  ----------------------------------------- -------- ----------------------------

  22.  validno NOT NULL VARCHAR2(30)
  23.  comcode NOT NULL CHAR(4)
  24.  ownername NOT NULL VARCHAR2(60)
  25.  ownertype NOT NULL CHAR(1)
  26.  identifytype NOT NULL CHAR(2)
  27.  identifynumber NOT NULL CHAR(20)
  28.  ***code CHAR(1)
  29.  postaddress VARCHAR2(120)
  30.  postcode CHAR(6)
  31.  phonenumber VARCHAR2(32)
  32.  companytype CHAR(3)

  33. SQL>




 

阅读(3944) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~