愿所有的美好和期待都能如约而至

VARCHAR2 10 CHAR 和 NVARCHAR2 10 的区别

发布时间:  来源:互联网  作者:匿名  标签:error Difference between VARCHAR2(10 CHAR) and NVARCHAR2(10) exception IT资讯 orac  热度:37.5℃

本文介绍了VARCHAR2(10 CHAR) 和 NVARCHAR2(10) 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用默认设置安装了 Oracle 数据库 10g 快捷版(通用):

I’ve installed Oracle Database 10g Express Edition (Universal) with the default settings:

SELECT * FROM NLS_DATABASE_PARAMETERS;

NLS_CHARACTERSET               AL32UTF8                                 
NLS_NCHAR_CHARACTERSET         AL16UTF16                                

鉴于 CHARNCHAR 数据类型似乎都接受多字节字符串,这两个列定义之间的确切区别是什么?

Given that both CHAR and NCHAR data types seem to accept multi-byte strings, what is the exact difference between these two column definitions?

VARCHAR2(10 CHAR)
NVARCHAR2(10)

推荐答案

NVARCHAR2 数据类型是由 Oracle 为数据库引入的,这些数据库希望对某些列使用 Unicode,同时为数据库的其余部分(使用 VARCHAR2)保留另一个字符集.NVARCHAR2 是仅限 Unicode 的数据类型.

The NVARCHAR2 datatype was introduced by Oracle for databases that want to use Unicode for some columns while keeping another character set for the rest of the database (which uses VARCHAR2). The NVARCHAR2 is a Unicode-only datatype.

您可能想要使用 NVARCHAR2 的一个原因可能是您的数据库使用非 Unicode 字符集,并且您仍然希望能够在不更改主要字符集的情况下为某些列存储 Unicode 数据.另一个原因可能是您想要使用两个 Unicode 字符集(AL32UTF8 用于主要来自西欧的数据,AL16UTF16 用于主要来自亚洲的数据),因为不同的字符集不会同样有效地存储相同的数据.

One reason you may want to use NVARCHAR2 might be that your DB uses a non-Unicode character set and you still want to be able to store Unicode data for some columns without changing the primary character set. Another reason might be that you want to use two Unicode character set (AL32UTF8 for data that comes mostly from western Europe, AL16UTF16 for data that comes mostly from Asia for example) because different character sets won’t store the same data equally efficiently.

示例中的两列(Unicode VARCHAR2(10 CHAR)NVARCHAR2(10))都能够存储相同的数据,但是字节存储将是不同的.某些字符串可能更有效地存储在其中一个中.

Both columns in your example (Unicode VARCHAR2(10 CHAR) and NVARCHAR2(10)) would be able to store the same data, however the byte storage will be different. Some strings may be stored more efficiently in one or the other.

另请注意,某些功能不适用于 NVARCHAR2,请参阅此 SO 问题:

Note also that some features won’t work with NVARCHAR2, see this SO question:

  • Oracle Text 将无法工作与 NVARCHAR2.还有什么可能不可用?

这篇关于VARCHAR2(10 CHAR) 和 NVARCHAR2(10) 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP