字符集例子-同一字符不同字符集编码不同及导入导出的乱码
2013-10-10 16:26
399 查看
1.演示相同的字符,在不同的字符集下,对应的编码不同的例子。
会话1:使用ZHS16GBK字符集[oracle@bys001 ~]$ export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
[oracle@bys001 ~]$ echo $NLS_LANG
AMERICAN_AMERICA.ZHS16GBK
[oracle@bys001 ~]$ sqlplus bys/bys
BYS@bys1>insert into test values(1,'白');
1 row created.
BYS@bys1>commit;
Commit complete.
BYS@bys1>select * from test;
ID NAME
---------- --------------------
1 白
会话2:会话2的如果使用ZHS32GB18030、ZHS16CGB231280字符集插入后编码和ZHS16GBK字符集的相同。
这里使用US7ASCII来测试。
[oracle@bys001 ~]$ export NLS_LANG=AMERICAN_AMERICA.US7ASCII
[oracle@bys001 ~]$ echo $NLS_LANG
AMERICAN_AMERICA.US7ASCII
[oracle@bys001 ~]$ sqlplus bys/bys
BYS@bys1>insert into test values(2,'白');
1 row created.
BYS@bys1>commit;
Commit complete.
在会话2查询:已经显示为乱码了。
BYS@bys1>select * from test;
ID NAME
---------- ----------
1 ?
2 ??
在会话1查询:会话2插入的汉字成了乱码,因为会话2是US7ASCII,
BYS@bys1>select * from test;
ID NAME
---------- --------------------
1 白
2 ??
查询字符编码,第一次插入和第二次的不同:
BYS@bys1>col aa for a60
BYS@bys1>select id,dump(name,1016) as aa from test;
ID AA
---------- ------------------------------------------------------------
1 Typ=1 Len=3 CharacterSet=AL32UTF8: e7,99,bd
2 Typ=1 Len=6 CharacterSet=AL32UTF8: ef,bf,bd,ef,bf,bd
######################################################################
3.将客户端设置为不同的字符集,演示导入/导出可能产生的乱码问题。
方法一:使用ZHS16GBK字符集,可以正常导出导入,此过程不产生乱码。[oracle@bys001 ~]$ echo $NLS_LANG
AMERICAN_AMERICA.ZHS16GBK
[oracle@bys001 ~]$ sqlplus bys/bys
BYS@bys1>select * from test;
ID NAME
---------- --------------------
1 白
2 ??
BYS@bys1>
BYS@bys1>exit
[oracle@bys001 ~]$ echo $NLS_LANG
AMERICAN_AMERICA.ZHS16GBK
[oracle@bys001 ~]$ exp bys/bys file='/home/oracle/test.dmp' tables=test rows=y
Export: Release 11.2.0.1.0 - Production on Sun Aug 11 00:49:34 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table TEST 2 rows exported
Export terminated successfully without warnings.
[oracle@bys001 ~]$ sqlplus bys/bys
BYS@bys1>select * from test;
ID NAME
---------- --------------------
1 白
2 ??
BYS@bys1>truncate table test;
Table truncated.
BYS@bys1>exit
[oracle@bys001 ~]$ imp bys/bys file='/home/oracle/test.dmp' full=y ignore=y
Import: Release 11.2.0.1.0 - Production on Sun Aug 11 00:50:22 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in ZHS16GBK character set and UTF8 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing BYS's objects into BYS
. importing BYS's objects into BYS
. . importing table "TEST" 2 rows imported
Import terminated successfully without warnings.
[oracle@bys001 ~]$ sqlplus bys/bys
BYS@bys1>select * from test;
ID NAME
---------- --------------------
1 白
2 ??
方法二:
[oracle@bys001 ~]$ export NLS_LANG=AMERICAN_AMERICA.US7ASCII
[oracle@bys001 ~]$ echo $NLS_LANG
AMERICAN_AMERICA.US7ASCII
[oracle@bys001 ~]$ rm -rf test.dmp
[oracle@bys001 ~]$ exp bys/bys file='/home/oracle/test.dmp' tables=test rows=y
Export: Release 11.2.0.1.0 - Production on Sun Aug 11 00:58:27 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
. . exporting table TEST 2 rows exported
Export terminated successfully without warnings.
[oracle@bys001 ~]$ imp bys/bys file='/home/oracle/test.dmp' full=y ignore=y
Import: Release 11.2.0.1.0 - Production on Sun Aug 11 01:00:36 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
import done in US7ASCII character set and UTF8 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing BYS's objects into BYS
. importing BYS's objects into BYS
. . importing table "TEST" 2 rows imported
Import terminated successfully without warnings.
[oracle@bys001 ~]$ sqlplus bys/bys
BYS@bys1>select * from test;
ID NAME
---------- ----------
1 ?
2 ??
相关文章推荐
- 字符集例子-同一字符不同字符集编码不同及导入导出的乱码
- 将客户端设置为不同的字符集,演示导入/导出可能产生的乱码问题。为什么没有出现乱码
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- 关于Oracle字符集在dmp文件导入导出中的乱码影响
- Oracle11g创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题
- 关于从服务器oracle11g上导出的sql (编码格式不同时)再导入到本地oracle11g上时乱码的处理的
- 【poi excel导出】不同浏览器的编码方式,解决下载文件名称乱码
- 编码--Phpmyadmin导入导出显示中文乱码
- Oracle11g创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题
- linux 下 mysql 修改密码 修改 字符集 乱码 数据库 导入 导出 添加远程访问
- (---关于oracle服务器和客户端字符集---)导出的pde是正常的(因为通过其他的plsql中导入没有问题),但是通过plsql导入后,显示乱码,怎么解决?
- 从MySQL导出导入数据库的命令实例及设置会话字符编码
- oracle 10g 字符集不同的库之间的数据导入导出问题
- Oracle11g创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题
- 不同编码引发的QueryString传参乱码
- mysql 导出乱码解决(导入远程服务器)
- ArcGIS Engine不同格式数据打开,对象创建,导入导出
- 不同字符集写文件的乱码问题
- 字符、字符集、编码——Something Every Programmer Should Know About
- 不同字符编码格式之间的转换