Oracle 中的多字节字符

jho*_*ith 2 oracle

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

\n\n
select length('\xe6\x9c\x89\xe4\xb8\xaa\xe5\x8f\xaf\xe7\x88\xb1\xe7\x9a\x84\xe5\xb0\x8f\xe5\xa8\x83\xe5\x9c\xa8\xe6\x97\x81\xe8\xbe\xb9') from dual;\n10\ndrop table multibyte;\ncreate table multibyte (name varchar2(10));\ninsert into multibyte\nvalues('\xe6\x9c\x89\xe4\xb8\xaa\xe5\x8f\xaf\xe7\x88\xb1\xe7\x9a\x84\xe5\xb0\x8f\xe5\xa8\x83\xe5\x9c\xa8\xe6\x97\x81\xe8\xbe\xb9');\n
Run Code Online (Sandbox Code Playgroud)\n\n

我收到一条错误消息说

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

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

\n

Jef*_*emp 6

区别在于列的定义:VARCHAR2(10)相当于VARCHAR2(10 BYTE),而您想要的是VARCHAR2(10 CHAR)

列数据类型中 BYTE 和 CHAR 的区别