char ,varchar2和varchar的区别

本文介绍了Oracle数据库中VARCHAR、VARCHAR2和CHAR三种数据类型。目前VARCHAR与VARCHAR2同义,但未来VARCHAR可能有不同比较语义。VARCHAR2是Oracle独特类型,保证版本兼容;VARCHAR是标准SQL类型。还说明了CHAR为定长,VARCHAR2为变长,以及使用建议。

http://blog.youkuaiyun.com/ntljy/archive/2004/06/30/30966.aspx 

http://www.itpub.net/showthread.php?threadid=36214&pagenumber=

Currently, 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 


-----------------------------

varchar -- 存放定長的字符數據,最長2000個字符;
varchar2 -- 存放可變長字符數據,最大長度為4000字符。

-----------------------------

目前没有本质的区别

但是:
varchar2是oracle提供的独特的数据类型
oracle保证在任何版本中该数据类型向上和向下兼容
但不保证varchar,这是因为varchar是标准sql提供的数据类型
有可能随着sql标准的变化而改变

----------------------------

1: char
CHAR Datatype
The CHAR datatype specifies a fixed-length character string. Oracle subsequently
ensures that all values stored in that column have the length specified by size. If you insert a value that is shorter than the column length, then Oracle blank-pads the value to column length. If you try to insert a value that is too long for the column, then Oracle returns an error.
The default length for a CHAR column is 1 byte and the maximum allowed is 2000
bytes. A 1-byte string can be inserted into a CHAR(10) column, but the string is
blank-padded to 10 bytes before it is stored.
2: varchar2
VARCHAR2 Datatype
The VARCHAR2 datatype specifies a variable-length character string. When you
create a VARCHAR2 column, you supply the maximum number of bytes or
characters of data that it can hold. Oracle subsequently stores each value in the column exactly as you specify it, provided the value does not exceed the column’s maximum length. If you try to insert a value that exceeds the specified length, then Oracle returns an error.
You must specify a maximum length for a VARCHAR2 column. This maximum must
be at least 1 byte.
3: varchar
VARCHAR Datatype
The VARCHAR datatype is currently synonymous with the VARCHAR2 datatype.
Oracle recommends that you use VARCHAR2 rather than VARCHAR. In the future,
VARCHAR might be defined as a separate datatype used for variable-length character strings compared with different comparison semantics.


--------------------------------------

char对于不够位数的用空格添补,varchar2不用。可以试着比较一下。

---------------------------

varchar2和varchar的目前没有区别,不过ocacle以后的版本就不支持varchar类型,如果想新版本的数据库兼容就不要用varchar,如果想和其它数据库兼容就不要用varchar2

---------------------------

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/35489/viewspace-84321/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/35489/viewspace-84321/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值