大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 数据库 -> ORACLE -> 字符集问题的初步探讨

字符集问题的初步探讨

时间: 2021-08-13 作者:daque

4. 导出导出及变换   导出导出是咱们常用的一个数据迁徙及变化东西,因其导出文献具备平台无干性,以是在跨平台迁徙中,最为常用。 在导出操纵时,特殊要害的是存户端的字符集树立,也即是存户端的nls_lang树立。 nls_lang参数由以次局部构成: nls_lang=<language>_<territory>.<clients characterset> nls_lang各局部含意如次: language指定: -oracle动静运用的谈话 -日子中月份和日表露 territory指定 -钱币和数字方法 -地域和计划礼拜及日子的风气 characterset: -遏制存户端运用步调运用的字符集 常常树立大概即是存户端(如windows)代码页  大概对于unicode运用树立为utf8 在windows上察看暂时体例的代码页不妨运用chcp吩咐: e:\>chcp  震动的代码页: 936 代码页936也即是中笔墨符集 gbk,在microsoft的官方站点上,咱们不妨受到对于936代码页的简直源代码准则,请参考以次链接: http://www.microsoft.com/globaldev/reference/dbcs/936.htm 咱们看一个大略的尝试,来领会一下这几个参数的效率:  e:\>set nls_lang=simplified chinese_china.zhs16gbk e:\>sqlplus "/ as sysdba" sql*plus: release 9.2.0.4.0 - production on 礼拜六 11月 1 22:51:59 2003 copyright (c) 1982, 2002, oracle corporation.  all rights reserved. 贯穿到: oracle9i enterprise edition release 9.2.0.4.0 - production with the partitioning, oracle label security, olap and oracle data mining options jserver release 9.2.0.4.0 - production sql> select sysdate from dual; sysdate ---------- 01-11月-03 已采用 1 行。 sql> exit 从oracle9i enterprise edition release 9.2.0.4.0 - production with the partitioning, oracle label security, olap and oracle data mining options jserver release 9.2.0.4.0 - production阻碍开 e:\>set nls_lang=american_america.zhs16gbk e:\>sqlplus "/ as sysdba" sql*plus: release 9.2.0.4.0 - production on sat nov 1 22:52:24 2003 copyright (c) 1982, 2002, oracle corporation.  all rights reserved. connected to: oracle9i enterprise edition release 9.2.0.4.0 - production with the partitioning, oracle label security, olap and oracle data mining options jserver release 9.2.0.4.0 - production sql> select sysdate from dual; sysdate --------- 01-nov-03 1 row selected. sql>      察看存户端nls_lang树立不妨运用以次本领: windows运用: echo %nls_lang% 如: e:\>echo %nls_lang% american_america.zhs16gbk unix运用: env|grep nls_lang 如: /opt/oracle>env|grep nls_lang nls_lang=american_china.zhs16gbk  windows存户端树立,不妨在备案表中变动nls_lang,简直键值坐落: hkey_local_machine\software\oracle\homexx\ xx指生存多个oracle_home时体例编号。 导出和导出是存户端产物,同sql*plus和oralce forms一律,所以,运用exp/imp东西将依照nls_lang设置的办法变换字符集。 导出运用的字符集将会记载在导出文献中,当文献导时髦,将会查看导出时运用的字符集树立,即使这个字符集各别于导出存户端的nls_lang 树立,字符集将按照导出存户端nls_lang树立举行变换,即使需要,在数据插入数据库之前会进前进一步变换。 常常在导出时最佳把存户端字符集树立得和数据库端沟通,如许不妨制止在导出时爆发不需要的数据变换,导出文献将和数据库具备沟通的字符集。 纵然未来会把导出文献导出到各别字符集的数据库中,如许做也不妨把变换减速至导时髦刻。 当举行数据导时髦,重要生存以次两种情景: 1.源数据库和目的数据库具备沟通字符集树立 这时候,只须要树立nls_lang即是数据库字符集即可导出(基础是,导出运用的是和源数据库沟通字符集,即三者沟通)  2.源数据库和目的数据库字符集各别 即使咱们导出功夫运用的nls_lang是和源数据库沟通的字符集,那么导时髦就不妨树立存户端nls_lang即是导出时运用的字符集,这 样变换只爆发在数据库端,并且只爆发一次。 比方: 即使举行从we8mswin1252到utf8的变换 1)运用nls_lang=american_america.we8mswin1252导出数据库。 这时候创造的导出文献包括we8mswin1252的数据 2)导时髦运用nls_lang=american_america.we8mswin1252 这时候变换仅爆发在insert数据到utf8的数据库中。 之上假如的变换只在目的数据库字符集是源数据库字符集的超集时本领变换。即使各别,普遍就须要举行少许特出的处置。 咱们大略看一下导出的变换进程(以oracle8i为例): 1.决定导出数据库字符集情况 经过读取导出文献头,不妨赢得导出文献的字符集树立 2.决定导出session的字符集,即导出session运用的nls_lang情况变量 3.imp读取导出文献 读取导出文献字符集id,和导出过程的nls_lang举行比拟 4.即使导出文献字符集和导出session字符集沟通,那么在这一办法内就不须要变换 即使各别,就须要把数据变换为导出session运用的字符集。 但是这种变换只能在单byte字符集之间举行。 咱们看一个尝试:   e:\nls2>set nls_lang=american_america.us7ascii 树立导出session nls_lang为us7ascii e:\nls2>e:\oracle\ora8i\bin\imp eygle/eygle file=sus7ascii-cus7ascii-exp817.dmp fromuser=eygle touser=eygle tables=test 这个导出文献是从us7ascii数据库导出,导出存户端nls_lang也是us7ascii import: release 8.1.7.1.1 - production on fri nov 7 00:59:22 2003 (c) copyright 2000 oracle corporation.  all rights reserved. connected to: oracle8i enterprise edition release 8.1.7.1.1 - production with the partitioning option jserver release 8.1.7.1.1 - production 这时候导出,在dmp文献和nls_lang之间不须要举行字符集变换。 export file created by export:v08.01.07 via conventional path import done in us7ascii character set and zhs16gbk nchar character set import server uses zhs16gbk character set (possible charset conversion) export server uses utf8 nchar character set (possible ncharset conversion) . . importing table                         "test"          2 rows imported import terminated successfully without warnings.      5.对于多byte字符集的导出(如:utf8) 须要树立导出session字符集和导出字符集沟通 要不就会遇到:imp-16 "required character set conversion (type %lu to %lu) not supported" 缺点。 : e:\nls2>set nls_lang=american_america.zhs16gbk 导出session字符集树立为zhs16gbk 导出us7ascii的导出文献 e:\nls2>e:\oracle\ora8i\bin\imp eygle/eygle file=sus7ascii-cus7ascii-exp817.dmp fromuser=eygle touser=eygle import: release 8.1.7.1.1 - production on fri nov 7 00:38:55 2003 (c) copyright 2000 oracle corporation.  all rights reserved. connected to: oracle8i enterprise edition release 8.1.7.1.1 - production with the partitioning option jserver release 8.1.7.1.1 - production imp-00016: required character set conversion (type 1 to 852) not supported imp-00000: import terminated unsuccessfully 在从导出文献us7ascii到导出 nls_lang树立为zhs16gbk的进程中,不扶助单byte字符集向多byte变换,报出之上缺点。      6.导出session字符集该当是导出字符集的超等,要不,私有的字符将难以精确变换。 7.当数据变换为导出session字符集树立此后,即使导出session字符集各别于导出数据库字符集,这时候还须要结果一步变换,这诉求导出数据库字符 集是导出session字符集的超等,要不某些私有字符将不许平常变换。 咱们连接看上头的两个进程,这边有如许两个规则: 1.即使nls_lang的树立和数据库沟通,那么数据(在传输进程中固然是2进制码)不过程变换就径直插入数据库中。 2.即使nls_lang的树立和数据库各别,那么数据须要变换后本领插入数据库中。 咱们再回顾来看上头的第一个例子: : export file created by export:v08.01.07 via conventional path import done in us7ascii character set and zhs16gbk nchar character set import server uses zhs16gbk character set (possible charset conversion) export server uses utf8 nchar character set (possible ncharset conversion) . . importing table                         "test"          2 rows imported import terminated successfully without warnings. 这功夫过程第一步变换后的数据,us7ascii到zhs16gbk丧失首位,原样插入数据库,咱们看到这时候数据库中寄存的即是缺点的字符(在反面局部咱们做了精细的变换): e:\nls2>sqlplus eygle/eygle sql*plus: release 9.2.0.4.0 - production on fri nov 7 00:35:39 2003 copyright (c) 1982, 2002, oracle corporation.  all rights reserved. connected to: oracle8i enterprise edition release 8.1.7.1.1 - production with the partitioning option jserver release 8.1.7.1.1 - production sql> select * from test; name -------------------- 2bjt test      在oracle9i中,之上情景略有各别。 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.