创建表格:
CREATE TABLE test (
charcol CHAR(10),
varcharcol VARCHAR2(10));
SELECT LENGTH(charcol), LENGTH(varcharcol) FROM test;
结果:
LENGTH(CHARCOL) LENGTH(VARCHARCOL)
--------------- ------------------
10 1
请让我知道 Varchar2 和 char 有什么区别?我们什么时候使用两者?
Please Let me know what is the difference between Varchar2 and char? At what times we use both?
简单的例子来说明区别:
Simple example to show the difference:
SELECT
'"'||CAST('abc' AS VARCHAR2(10))||'"',
'"'||CAST('abc' AS CHAR(10))||'"'
FROM dual;
'"'||CAST('ABC'ASVARCHAR2(10))||'"' '"'||CAST('ABC'ASCHAR(10))||'"'
----------------------------------- -------------------------------
"abc" "abc "
1 row selected.
CHAR 对于字符长度总是固定的表达式很有用,例如美国各州的邮政编码,例如 CA、NY、FL、TX
The CHAR is usefull for expressions where the length of charaters is always fix, e.g. postal code for US states, for example CA, NY, FL, TX
这篇关于Varchar2 和 char 之间的主要区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!