Oracle / JDBC: retrieving TIMESTAMP WITH TIME ZONE value in ISO 8601 format

前端 未结 7 1946
抹茶落季
抹茶落季 2020-12-13 10:58

A lot have been said (and written on SO) on parts of the subject, but not in a comprehensive, complete way, so we can have one \"ultimate, covering-it-all\" solution for eve

7条回答
  •  囚心锁ツ
    2020-12-13 11:36

    A slight improvement to #2:

    CREATE OR REPLACE PACKAGE FORMAT AS
      FUNCTION TZ(T TIMESTAMP WITH TIME ZONE) RETURN VARCHAR2;
    END;
    /
    CREATE OR REPLACE PACKAGE BODY FORMAT AS
      FUNCTION TZ(T TIMESTAMP WITH TIME ZONE) RETURN VARCHAR2
      AS
      BEGIN
        RETURN TO_CHAR(T,'YYYYMMDD"T"HH24:MI:SS.FFTZHTZM');
      END;
    END;
    /
    

    The in SQL this becomes:

    SELECT FORMAT.TZ(tstz) EVENT_TIME ...
    

    It's more readable.
    If you ever need to change it, it's 1 place.
    The downside is it is an extra function call.

提交回复
热议问题