Forum Stats

  • 3,837,399 Users
  • 2,262,255 Discussions
  • 7,900,269 Comments

Discussions

date

2839801
2839801 Member Posts: 68
edited Dec 4, 2015 10:33PM in SQLとPL/SQL

what is trunc(date)?

Best Answer

  • Papageno
    Papageno Member Posts: 53 Bronze Badge
    edited Dec 4, 2015 10:33PM Answer ✓

    SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY/MM/DD HH24:MI:SS' ;

    Session altered.

    SQL> SELECT SYSDATE

      2       , TRUNC(SYSDATE, 'MI') AS TRUNC_MI

      3       , TRUNC(SYSDATE, 'HH') AS TRUNC_HH

      4       , TRUNC(SYSDATE)       AS TRUNCED

      5       , TRUNC(SYSDATE, 'MM') AS TRUNC_MM

      6       , TRUNC(SYSDATE, 'YY') AS TRUNC_YY

      7  FROM DUAL ;

    SYSDATE             TRUNC_MI            TRUNC_HH            TRUNCED             TRUNC_MM            TRUNC_YY

    ------------------- ------------------- ------------------- ------------------- ------------------- -------------------

    2015/12/05 09:12:45 2015/12/05 09:12:00 2015/12/05 09:00:00 2015/12/05 00:00:00 2015/12/01 00:00:00 2015/01/01 00:00:00

Answers

  • Jagadekara
    Jagadekara Member Posts: 1,860 Gold Trophy
    edited Dec 1, 2015 12:54AM
  • Papageno
    Papageno Member Posts: 53 Bronze Badge
    edited Dec 4, 2015 10:33PM Answer ✓

    SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY/MM/DD HH24:MI:SS' ;

    Session altered.

    SQL> SELECT SYSDATE

      2       , TRUNC(SYSDATE, 'MI') AS TRUNC_MI

      3       , TRUNC(SYSDATE, 'HH') AS TRUNC_HH

      4       , TRUNC(SYSDATE)       AS TRUNCED

      5       , TRUNC(SYSDATE, 'MM') AS TRUNC_MM

      6       , TRUNC(SYSDATE, 'YY') AS TRUNC_YY

      7  FROM DUAL ;

    SYSDATE             TRUNC_MI            TRUNC_HH            TRUNCED             TRUNC_MM            TRUNC_YY

    ------------------- ------------------- ------------------- ------------------- ------------------- -------------------

    2015/12/05 09:12:45 2015/12/05 09:12:00 2015/12/05 09:00:00 2015/12/05 00:00:00 2015/12/01 00:00:00 2015/01/01 00:00:00

This discussion has been closed.