Character Data Types

CHAR Data Type
The CHAR data type specifies a fixed-length character string(固定长度). Oracle ensures(保证) that all values stored in a CHAR column have the length specified by size. If you insert a value that is shorter than the column length, then Oracle blank-pads(空白填充) the value to column length. If you try to insert a value that is too long for the column, then Oracle returns an error.

The default length for a CHAR column is 1 byte and the maximum allowed is 2000 bytes. A 1-byte string can be inserted into a CHAR(10) column, but the string is blank-padded to 10 bytes before it is stored.

When you create a table with a CHAR column, by default you supply(提供) the column length in bytes. The BYTE qualifier(修饰符) is the same as the default. If you use the CHAR qualifier, for example CHAR(10 CHAR), then you supply the column length in characters. A character is technically a code point of the database character set(数据库字符集). Its size can range from 1 byte to 4 bytes, depending on the database character set. The BYTE and CHAR qualifiers override(覆盖) the semantics(语义) specified by the NLS_LENGTH_SEMANTICS parameter, which has a default of byte semantics. For performance reasons(出于性能的考虑), Oracle recommends(推荐) that you use the NLS_LENGTH_SEMANTICS parameter to set length semantics and that you use the BYTE and CHAR qualifiers only when necessary to override the parameter.

To ensure proper data conversion(数据转换) between databases with different character sets, you
must ensure that CHAR data consists of(由 … 组成) well-formed strings.

NCHAR Data Type
The NCHAR data type is a Unicode-only data type. When you create a table with an
NCHAR column, you define the column length in characters. You define the national
character set when you create your database.
The maximum length of a column is determined by the national character set(国家字符集)
definition. Width specifications of character data type NCHAR refer to the number of
characters. The maximum column size allowed is 2000 bytes.
If you insert a value that is shorter than the column length, then Oracle blank-pads the
value to column length. You cannot insert a CHAR value into an NCHAR column, nor can
you insert an NCHAR value into a CHAR column.
The following example compares(比较) the translated_description column of the
pm.product_descriptions table with a national character set string:

SELECT translated_description
 FROM product_descriptions
 WHERE translated_name = N'LCD Monitor 11/PM'; 

NVARCHAR2 Data Type
The NVARCHAR2 data type is a Unicode-only data type. When you create a table with an NVARCHAR2 column, you supply the maximum number of characters it can hold(支持). Oracle subsequently(随后) stores each value in the column exactly as(正如) you specify it, provided the value does not exceed(超过) the maximum length of the column. The maximum length of the column is determined by the national character set definition. Width specifications(宽度规格) of character data type NVARCHAR2 refer to the number of characters. The maximum column size allowed is:
■ 32767 bytes if MAX_STRING_SIZE = EXTENDED
■ 4000 bytes if MAX_STRING_SIZE = STANDARD

VARCHAR2 Data Type
The VARCHAR2 data type specifies a variable-length character string. When you create a VARCHAR2 column, you supply the maximum number of bytes or characters of data that it can hold. Oracle subsequently stores each value in the column exactly as you specify it, provided the value does not exceed the maximum length of the column. If you try to insert a value that exceeds the specified length, then Oracle returns an error.
You must specify a maximum length for a VARCHAR2 column. This maximum must be at least 1 byte, although the actual(实际上) string stored is permitted(允许) to be a zero-length string (”). You can use the CHAR qualifier, for example VARCHAR2(10 CHAR), to give the maximum length in characters instead of bytes. A character is technically a code point of the database character set. You can use the BYTE qualifier, for example VARCHAR2(10 BYTE), to explicitly(明确地) give the maximum length in bytes. If no explicit qualifier is included in a column or attribute(属性) definition when a database object with this column
or attribute is created, then the length semantics are determined by the value of the
NLS_LENGTH_SEMANTICS parameter of the session creating the object. Independently of(独立)
the maximum length in characters, the length of VARCHAR2 data cannot exceed:
■ 32767 bytes if MAX_STRING_SIZE = EXTENDED
■ 4000 bytes if MAX_STRING_SIZE = STANDARD
Refer to “Extended Data Types” on page 2-27 for more information on the MAX_STRING_
SIZE initialization parameter and the internal storage mechanisms for extended data
types.
Oracle compares VARCHAR2 values using nonpadded(非填充) comparison semantics.
To ensure proper data conversion between databases with different character sets, you
must ensure that VARCHAR2 data consists of well-formed strings. See **Oracle Database
Globalization Support Guide** for more information on character set support.

VARCHAR Data Type
Do not use the VARCHAR data type. Use the VARCHAR2 data type instead. Although the
VARCHAR data type is currently synonymous(目前同义词) with VARCHAR2, the VARCHAR data type is
scheduled to(定于) be redefined as a separate(独立的) data type used for **variable-length character
strings** compared with different comparison semantics.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值