列数据类型中BYTE和CHAR之间的区别 [英] Difference between BYTE and CHAR in column datatypes

查看:133
本文介绍了列数据类型中BYTE和CHAR之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle中,:

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最新版本中的推荐设置.在这种情况下,某些字符需要占用一个以上的字节才能存储在数据库中.

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之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆