Chinaunix首页 | 论坛 | 博客
  • 博客访问: 429412
  • 博文数量: 55
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1584
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-04 15:15
个人简介

热衷技术,热爱交流

文章分类

全部博文(55)

文章存档

2014年(7)

2013年(48)

分类: Oracle

2013-06-14 00:11:48

The length semantics of character data types can be measured in bytes or characters. Byte semantics treat strings as a sequence of bytes. This is
the default for character data types. Character semantics treat strings as a sequence of characters. A character is technically a code point of the

database character set.

Oracle字符数据类型的长度语义有两种,即字节语义和字符语义。varchar2按照字节长度语义来限定字符串长度,而nvarchar2按照字符长度语义限定字符串长度。

查看数据库的字符集:

HR >select PARAMETER,value from v$nls_parameters where parameter like '%CHARACTERSET%';

PARAMETER                     |VALUE

------------------------------|------------------------------

NLS_CHARACTERSET              |ZHS16GBK

NLS_NCHAR_CHARACTERSET   |AL16UTF16

测试varchar2(一个汉字占用两个字节):

HR >create table test(id varchar2(5)); 

HR >insert into test values('你好');

1 row created.

HR >insert into test values('你好a');

1 row created.

HR >insert into test values('你好啊');

insert into test values('你好啊')

ERROR at line 1:

ORA-12899: "HR"."TEST"."ID" 的值太大 (实际值: 6, 最大值: 5)

Elapsed: 00:00:00.01

           Nvarchar2字符类型存储的是unicode字符集数据,本例是AL16UTF16,它可以存放几乎所有国家的字符。当创建国家字符类型属性时候,最大长度始终
          是字符长度语义(
When you        create a table with an NCHAR or NVARCHAR2 column, the  maximum size is always in character length semantics

          测试nvarchar(2):

      HR >drop table test;

     Table dropped.

     HR >create table test(id nvarchar2(5));                  

     HR >insert into test values('你好啊是吗');

     1 row created.

     HR >insert into test values('你好啊是吗不是');

     insert into test values('你好啊是吗不是')                       *

     ERROR at line 1:

     ORA-12899: "HR"."TEST"."ID" 的值太大 (实际值: 7, 最大值: 5)

     HR >insert into test values('aaaaaa');       

     insert into test values('aaaaaa')

                        *

     ERROR at line 1:

     ORA-12899: "HR"."TEST"."ID" 的值太大 (实际值: 6, 最大值: 5)

阅读(2135) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~