NVARCHAR2、VARCHAR2区别

来源:互联网 发布:出售淘宝卖家帐号 编辑:程序博客网 时间:2024/06/05 07:41

源自:http://www.cnblogs.com/flyingfish/archive/2010/01/15/1648448.html

Oralce官方文档“Datatypes”部分对NVARCHAR2、VARCHAR2以及VARCHAR有一段描述,可以清晰得到它们的区别。罗列在此,供大家参考。
【链接】http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#sthref71

NVARCHAR2Datatype

The NVARCHAR2 datatype is a Unicode-only datatype. When you createa table with an NVARCHAR2 column, you supply the maximum number ofcharacters it can hold. Oracle subsequentlystores each value in the column exactly as you specify it, providedthe value does not exceed the maximum length of thecolumn.

The maximum length of the column is determined by the nationalcharacter set definition. Width specifications of characterdatatype NVARCHAR2 refer to the number of characters. The maximumcolumn size allowed is 4000 bytes. Please refer to Oracle DatabaseGlobalization Support Guide for information on Unicode datatypesupport.

VARCHAR2 Datatype

The VARCHAR2 datatype specifies a variable-length character string.When you create a VARCHAR2 column, you supply the maximum number ofbytes or characters of data that it can hold. Oracle subsequentlystores each value in the column exactly as you specify it, providedthe value does not exceed the column's maximum length of thecolumn. If you try to insert a value that exceeds the specifiedlength, then Oracle returns an error.

You must specify a maximum length for a VARCHAR2 column. Thismaximum must be at least 1 byte, although the actual string storedis permitted to be a zero-length string (''). You can use the CHARqualifier, for example VARCHAR2(10 CHAR), to give the maximumlength in characters instead of bytes. A character is technically acode point of the database character set. CHAR and BYTE qualifiersoverride the setting of the NLS_LENGTH_SEMANTICS parameter, whichhas a default of bytes. For performance reasons, Oracle recommendsthat you use the NLS_LENGTH_SEMANTICS parameter to set lengthsemantics and that you use the BYTE and CHAR qualifiers only whennecessary to override the parameter. The maximum length of VARCHAR2data is 4000 bytes. Oracle compares VARCHAR2 values using nonpaddedcomparison semantics.

To ensure proper data conversion between databases with differentcharacter sets, you must ensure that VARCHAR2 data consists ofwell-formed strings. See Oracle Database Globalization SupportGuide for more information on character setsupport.

VARCHAR Datatype

Do not use the VARCHAR datatype. Use the VARCHAR2 datatype instead.Although the VARCHAR datatype is currently synonymous withVARCHAR2, the VARCHAR datatype is scheduled to be redefined as aseparate datatype used for variable-length character stringscompared with different comparison semantics.

【注意】
VARCHAR2是Oracle提供的特定数据类型,Oracle可以保证VARCHAR2在任何版本中该数据类型都可以向上和向下兼容。
VARCHAR在Oracle中不建议使用。

具体到NVARCHAR2和VARCHAR2的区别,从使用角度来看区别在于:NVARCHAR2在计算长度时和字符集相关的,例如数据库是中文字符集时以长度10为例,则

1、NVARCHAR2(10)是可以存进去10个汉字的,如果用来存英文也只能存10个字符。

2、而VARCHAR2(10)的话,则只能存进5个汉字,英文则可以存10个。  

0 0
原创粉丝点击