char ,varchar2和varchar的區別

tolywang發表於2005-04-05

http://blog.csdn.net/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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章