DB2_COMPATIBILITY_VECTOR=ORA, DATE type


When using Oracle compatibility features on DB2 9.7 (by setting DB2_COMPATIBILITY_VECTOR registry variable to ORA), DATE type columns are created and behave as TIMESTAMP.


The following example shows the DATE type column definition when DB2_COMPATIBILITY_VECTOR=ORA is set:

$ db2set -all
[i] DB2_COMPATIBILITY_VECTOR=ORA
[i] DB2COMM=TCPIP

$ db2 "create table test03(id integer, created_on date, create_at timestamp)"
DB20000I  The SQL command completed successfully.

$ db2 "describe table test03"

              Data type                 Column
Column name   schema    Data type name  Length  Scale Nulls
------------- --------- --------------- ------- ----- ------
ID            SYSIBM    INTEGER               4     0 Yes
CREATED_ON    SYSIBM    TIMESTAMP             7     0 Yes
CREATE_AT     SYSIBM    TIMESTAMP            10     6 Yes


This is an expected behavior as ORA (equivalent to the hexadecimal value 10FFF) value of DB2_COMPATIBILITY_VECTOR registry variable enables all of the supported Oracle compatibility features, including making the DATE data type to be changed to support applications that use the Oracle DATE data type expecting that the values include time information (for example, '2009-04-01-09.43.05').


Resolving the problem

In order to enable Oracle features by setting DB2_COMPATIBILITY_VECTOR registry variable to ORA but also keep the DB2 usual behavior for DATE column, DB2_COMPATIBILITY_VECTOR must be set to FBF, which means Oracle features (equivalent to the hexadecimal value 10FFF) minus DATE feature (equivalent to the hexadecimal value 0x40). So FFF-40 = FBF.


$ db2set DB2_COMPATIBILITY_VECTOR=FBF
$ db2set -all
[i] DB2_COMPATIBILITY_VECTOR=FBF
[i] DB2COMM=TCPIP

An instance recycle is necessary after setting DB2_COMPATIBILITY_VECTOR

$ db2 "create table test03(id integer, created_on date, create_at timestamp)"
DB20000I  The SQL command completed successfully.

$ db2 "describe table test03"

              Data type                 Column
Column name   schema    Data type name  Length Scale Nulls
------------- --------- -------------- ------- ----- ------
ID               SYSIBM  INTEGER           4     0    Yes
CREATED_ON       SYSIBM  DATE              4     0    Yes
CREATE_AT        SYSIBM  TIMESTAMP        10     6    Yes

  3 record(s) selected.

你可能感兴趣的:(DB2_COMPATIBILITY_VECTOR=ORA, DATE type)