VARCHAR2(10 CHAR)和NVARCHAR2(10)之间的区别 [英] Difference between VARCHAR2(10 CHAR) and NVARCHAR2(10)

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

问题描述

我已经使用默认设置安装了Oracle Database 10g Express Edition(通用):

SELECT * FROM NLS_DATABASE_PARAMETERS;

NLS_CHARACTERSET               AL32UTF8                                 
NLS_NCHAR_CHARACTERSET         AL16UTF16                                

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

VARCHAR2(10 CHAR)
NVARCHAR2(10)

解决方案

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

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

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

还请注意,某些功能不适用于NVARCHAR2,请参见以下SO问题:

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                                

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)

解决方案

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.

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.

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.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆