CHAR(2)和CHAR(2 CHAR)有什么区别? [英] What is the difference between CHAR(2) and CHAR(2 CHAR)?

查看:922
本文介绍了CHAR(2)和CHAR(2 CHAR)有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解,Char(2)长度为2个字节,CHAR(2个CHAR)长度为2个字符。但CHAR(2)也只能存储2个字符。请解释它们之间的区别。

谢谢。

As per my understanding Char(2) length is 2 bytes and for CHAR(2 CHAR) column length is 2 characters. But CHAR(2) will also store 2 characters only. Please explain the difference between them.
Thank you.

推荐答案

这就是字符的含义。通常(历史上)字符将存储在单个字节中。现在你可以有多字节字符(例如中文字符可以存储在数据库中)。



为了确保数据库可以处理这些并分配足够的空间,你可以坚持认为该字段可以容纳2个字符而不管用于表示每个字符的字节数。

CHAR(2) CHAR(2 BYTE)相同假定使用单字节字符。



本文是关于此主题的 - 字符语义 [ ^ ] - 并且比我的尝试解释得更好。它专注于varchar2,但同样适用于char。
This comes down what is meant by a "character". Typically (historically) a character would have been stored in a single byte. Nowadays you can have multi-byte characters (e.g. chinese characters can be stored on the database).

In order to ensure that the database can handle these and allocates sufficient space, you can insist that the field can hold 2 characters regardless of how many bytes are used to represent each character.
CHAR(2) is the same as CHAR(2 BYTE) which assumes single-byte characters are used.

This article is about this topic - "character semantics"[^] - and explains it better than my attempt. It focusses on varchar2 but the same applies to char.


这篇关于CHAR(2)和CHAR(2 CHAR)有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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