Database Character Set & National Character Set

本文详细介绍了Oracle数据库中使用的字符集及其对SQLCHAR数据类型、标识符和源代码的影响。特别关注了NCHAR和NVARCHAR2类型的Unicode特性,包括其存储方式、最大长度限制及与数据库字符集的关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://download.oracle.com/docs/cd/B10500_01/server.920/a96529/ch2.htm

Oracle uses the database character set for:

  • Data stored in SQL CHAR datatypes (CHAR, VARCHAR2, CLOB, and LONG)
  • Identifiers such as table names, column names, and PL/SQL variables
  • Entering and storing SQL and PL/SQL source code

The character encoding scheme used by the database is defined as part of the CREATE DATABASE statement. All SQL CHAR datatype columns (CHAR, CLOB, VARCHAR2, and LONG), including columns in the data dictionary, have their data stored in the database character set. In addition, the choice of database character set determines which characters can name objects in the database. SQL NCHAR datatype columns (NCHAR, NCLOB, and NVARCHAR2) use the national character set.


Note:

CLOB data is encoded as UCS-2 if the database character set is multibyte. If the database character set is single-byte, then CLOB data is stored in the database character set.


After the database is created, you cannot change the character sets, with some exceptions, without re-creating the database.

http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i3253

NCHAR and NVARCHAR2 Datatypes

NCHAR and NVARCHAR2 are Unicode datatypes that store Unicode character data. The character set of NCHAR and NVARCHAR2 datatypes can only be either AL16UTF16 or UTF8 and is specified at database creation time as the national character set. AL16UTF16 and UTF8 are both Unicode encoding.

  • The NCHAR datatype stores fixed-length character strings that correspond to the national character set.

  • The NVARCHAR2 datatype stores variable length character strings.

When you create a table with an NCHAR or NVARCHAR2 column, the maximum size specified is always in character length semantics. Character length semantics is the default and only length semantics for NCHAR or NVARCHAR2.

For example, if national character set is UTF8, then the following statement defines the maximum byte length of 90 bytes:

CREATE TABLE tab1 (col1 NCHAR(30));

This statement creates a column with maximum character length of 30. The maximum byte length is the multiple of the maximum character length and the maximum number of bytes in each character.

转载于:https://www.cnblogs.com/NickyYe/archive/2011/07/15/2107759.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值