问题描述
在Oracle中,有什么区别:
In Oracle, what is the difference between :
CREATE TABLE CLIENT
(
NAME VARCHAR2(11 BYTE),
ID_CLIENT NUMBER
)
和
CREATE TABLE CLIENT
(
NAME VARCHAR2(11 CHAR), -- or even VARCHAR2(11)
ID_CLIENT NUMBER
)
推荐答案
让我们假设数据库字符集是 UTF-8,这是 Oracle 最新版本中推荐的设置.在这种情况下,某些字符需要超过 1 个字节才能存储在数据库中.
Let us assume the database character set is UTF-8, which is the recommended setting in recent versions of Oracle. In this case, some characters take more than 1 byte to store in the database.
如果将字段定义为 VARCHAR2(11 BYTE)
,Oracle 最多可以使用 11 个字节进行存储,但实际上您可能无法在该字段中存储 11 个字符,因为某些它们需要一个以上的字节来存储,例如非英文字符.
If you define the field as VARCHAR2(11 BYTE)
, Oracle can use up to 11 bytes for storage, but you may not actually be able to store 11 characters in the field, because some of them take more than one byte to store, e.g. non-English characters.
通过将字段定义为 VARCHAR2(11 CHAR)
,您告诉 Oracle 它可以使用足够的空间来存储 11 个字符,无论存储每个字符需要多少字节.单个字符最多可能需要 4 个字节.
By defining the field as VARCHAR2(11 CHAR)
you tell Oracle it can use enough space to store 11 characters, no matter how many bytes it takes to store each one. A single character may require up to 4 bytes.
这篇关于列数据类型中 BYTE 和 CHAR 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!