Oracle中的多字节字符

时间:2012-11-22 03:09:13

标签: oracle

我想在Oracle数据库中插入中文字符。

select length('有个可爱的小娃在旁边') from dual;
10
drop table multibyte;
create table multibyte (name varchar2(10));
insert into multibyte
values('有个可爱的小娃在旁边');

我收到一条错误消息

           An attempt was made to insert or update a column with a value
           which is too wide for the width of the destination column.
           The name of the column is given, along with the actual width
           of the value, and the maximum allowed width of the column.
           Note that widths are reported in characters if character length
           semantics are in effect for the column, otherwise widths are
           reported in bytes

我知道如果我增加列宽,问题就可以消失了。 我的问题是,当长度函数告诉我宽度为10时为什么我不能将它插入到varchar2(10)的列中?

2 个答案:

答案 0 :(得分:4)

差异是由于列的定义:VARCHAR2(10)相当于VARCHAR2(10 BYTE),而您想要的是VARCHAR2(10 CHAR)

Difference between BYTE and CHAR in column datatypes

答案 1 :(得分:1)

是的,这有点不幸。 Oracle以字节为单位测量文本列长度,因此varchar2(10)只能存储10个字节,大约是3个中文字符。

相关问题