天天看點

oracle資料類型varchar2和varchar的差別

varchar -- 存放定長的字元數據,最長2000個字元;

varchar2 -- 存放可變長字元數據,最大長度為4000字元。

目前沒有本質的差別

但是:

varchar2是oracle提供的獨特的資料類型

oracle保證在任何版本中該資料類型向上和向下相容

但不保證varchar,這是因為varchar是标準sql提供的資料類型

有可能随着sql标準的變化而改變

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