字符集问题的初步探讨(四)

来源:互联网 发布:js预加载页面动画 编辑:程序博客网 时间:2024/06/05 01:06
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

link:

http://www.eygle.com/special/NLS_CHARACTER_SET_04.htm

4.导入导出及转换

 

导入导出是我们常用的一个数据迁移及转化工具,因其导出文件具有平台无关性,所以在跨平台迁移中,最为常用。
在导出操作时,非常重要的是客户端的字符集设置,也就是客户端的NLS_LANG设置。
NLS_LANG参数由以下部分组成:







NLS_LANG=<Language>_<Territory>.<ClientsCharacterset>





NLS_LANG各部分含义如下:LANGUAGE指定:-消息使用的语言-日期中月份和日显示TERRITORY指定-货币和数字格式-地区和计算星期及日期的习惯CHARACTERSET:-控制客户端应用程序使用的字符集通常设置或者等于客户端(如Windows)代码页或者对于unicode应用设置为UTF8在Windows上查看当前系统的代码页可以使用chcp命令:

E:/>chcp
活动的代码页:936


代码页936也就是中文字符集GBK,在Microsoft的官方站点上,我们可以遭到关于936代码页的具体编码规则,请参考以下链接:


http://www.microsoft.com/globaldev/reference/dbcs/936.htm

我们看一个简单的测试,来了解一下这几个参数的作用:


 

E:/>setNLS_LANG=SIMPLIFIEDCHINESE_CHINA.ZHS16GBKE:/>sqlplus"/assysdba"SQL*Plus:Release9.2.0.4.0-Productionon星期六11月122:51:592003Copyright(c)1982,2002,OracleCorporation.Allrightsreserved.连接到:Oracle9iEnterpriseEditionRelease9.2.0.4.0-ProductionWiththePartitioning,OracleLabelSecurity,OLAPandOracleDataMiningoptionsJServerRelease9.2.0.4.0-ProductionSQL>selectsysdatefromdual;SYSDATE----------01-11月-03已选择1行。SQL>exit从Oracle9iEnterpriseEditionRelease9.2.0.4.0-ProductionWiththePartitioning,OracleLabelSecurity,OLAPandOracleDataMiningoptionsJServerRelease9.2.0.4.0-Production中断开E:/>setNLS_LANG=AMERICAN_AMERICA.ZHS16GBKE:/>sqlplus"/assysdba"SQL*Plus:Release9.2.0.4.0-ProductiononSatNov122:52:242003Copyright(c)1982,2002,OracleCorporation.Allrightsreserved.Connectedto:Oracle9iEnterpriseEditionRelease9.2.0.4.0-ProductionWiththePartitioning,OracleLabelSecurity,OLAPandOracleDataMiningoptionsJServerRelease9.2.0.4.0-ProductionSQL>selectsysdatefromdual;SYSDATE---------01-NOV-031rowselected.SQL>


查看客户端NLS_LANG设置可以使用以下方法:

Windows使用:echo%NLS_LANG%如:E:/>echo%NLS_LANG%AMERICAN_AMERICA.ZHS16GBKUnix使用:env|grepNLS_LANG如:/opt/oracle>env|grepNLS_LANGNLS_LANG=AMERICAN_CHINA.ZHS16GBKWindows客户端设置,可以在中更改NLS_LANG,具体键值位于:HKEY_LOCAL_MACHINEOFTWARE/ORACLE/HOMExx/xx指存在多个ORACLE_HOME时系统编号。

导入和导出是客户端产品,同SQL*PLUS和OralceForms一样,因此,使用EXP/IMP工具将按照NLS_LANG定义的方式转换字符集。

导出使用的字符集将会记录在导出文件中,当文件导入时,将会检查导出时使用的字符集设置,如果这个字符集不同于导入客户端的NLS_LANG
设置,字符集将根据导入客户端NLS_LANG设置进行转换,如果必要,在数据插入之前会进行进一步转换。

通常在导出时最好把客户端字符集设置得和数据库端相同,这样可以避免在导出时发生不必要的数据转换,导出文件将和数据库具有相同的字符集。
即使将来会把导出文件导入到不同字符集的数据库中,这样做也可以把转换延缓至导入时刻。

当进行数据导入时,主要存在以下两种情况:
1.源数据库和目标数据库具有相同字符集设置共3页  第1页  
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击