Search code examples
datedb2sqldatatypesdb2-luw

Why does DATE in DB2 database have a time component in it?


How can I make the column data type be DATE like YYYY-MM-DD;

when I create a table with the Data type DATE, it will become TIMESTAMP(0)

When I ALTER SET DATA TYPE DATE, it still is TIMESTAMP(0) and SELECT CHAR(CURRENT DATE, ISO) FROM SYSIBM.SYSDUMMY1; it will be error with SQLCODE=-171, CURRENT DATE is 2017-02-28 19:19:09.0 it's too long.

database info:DB2 linux x64 10.5

CREATE TABLE "XCRSUSR"."TIMP_TASK_SERIAL" (
        "SERIAL_NO" DECIMAL(16 , 0), 
        "TASK_NAME" VARCHAR(10), 
        "TASK_TYPE" DOUBLE, 
        "TASK_XML" CLOB(10) INLINE LENGTH 164, 
        "SEND_TIME" DATE, 
        "FINISH_TIME" DATE, 
        "TASK_STATUS" DOUBLE DEFAULT 0, 
        "RUN_TYPE" DOUBLE, 
        "FLAG" DOUBLE, 
        "TASK_ID" VARCHAR(10)
    )
    ORGANIZE BY ROW
    DATA CAPTURE NONE 
    IN "CREDIT_U_16" INDEX IN "CREDIT_INDEX_16"
    COMPRESS NO;

ALTER TABLE TIMP_TASK_SERIAL ALTER COLUMN SEND_TIME SET DATA TYPE DATE;
select CURRENT DATE from SYSIBM.SYSDUMMY1; 
 1
 ---------------------
 2017-02-28 19:19:09.0

Solution

  • Check out the settings of the

    Oracle_Compatibility

    vector under

    https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.apdv.porting.doc/doc/r0052867.html

    Bit Position 7 in table 1 is wjat you are looking for.