今天开发人员执行了一条命令:
alter table test1 modify column1 varchar(100);
我一般只知道varchar2()和char()的区别:
char()是定长的,如果实际字符长度不足,会用空格补齐;
varchar2()是变长的,字符占用的长度和实际字符一致。
我平时用类型也只用到过varchar2,但是从来没有用过varchar,当然也没有仔细研究。网上查了一些资料,找到如下解释:
VARCHAR is synonymous with VARCHAR2. However, in future releases of PL/SQL, to accommodate emerging SQL standards, VARCHAR might become a separate datatype with different comparison semantics. So, it is a good
idea to use VARCHAR2 rather than VARCHAR.
varchar2是oracle提供的独特的数据类型, oracle保证在任何版本中该数据类型向上和向下兼容
但不保证varchar,这是因为varchar是标准sql提供的数据类型 ,有可能随着sql标准的变化而改变。
VARCHAR
The VARCHAR datatype stores character strings of varying length. The first two bytes contain the length of the character string, and the remaining bytes contain the string. The specified length of the string in a bind or a define call must include the two length bytes, so the largest VARCHAR string that can be received or sent is 65533 bytes long, not 65535. For converting longer strings, use the LONG VARCHAR external datatype.
VARCHAR2
The VARCHAR2 datatype is a variable-length string of characters with a maximum length of 4000 bytes.
所以,虽然可以执行alter命令,oracle在存储内部也会把varchar()转换成varchar2(),但是还是建议开发人员使用varchar2().
参考文献:
1. http://www.itpub.net/viewthread.php?tid=36214&extra=&page=2
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9252210/viewspace-608960/ ,如需转载,请注明出处,否则将追究法律责任。