Oracle's default date format is YYYY-MM-DD, WHY?

后端 未结 12 2449
温柔的废话
温柔的废话 2020-11-29 00:44

Oracle\'s default date format is YYYY-MM-DD. Which means if I do:

 select some_date from some_table

...I lose the time portion of

相关标签:
12条回答
  • 2020-11-29 01:00

    Most of the IDE you can configure the default mask for some kind of data as date, currency, decimal separator, etc.

    If your are using Oracle SQL Developer:

    Tool > Preferences > Database > NLS

    Date Format: YYYY-MM-DD HH24:MI:SS

    0 讨论(0)
  • 2020-11-29 01:02

    To answer to your question that is WHY default date don't display TIME part, the only answer I find is

    Oracle teams are composed of LAZY developpers or responsibles :-)

    Why ?

    Because DATE, TIME and DATETIME datatypes exist in SQL and Oracle has not yet implemented it !!!

    It is a shame for Oracle.

    But the correct answer to your problem is not to define a FIX default format but a SIGNIFICANT default format that display only significant digits so that DATE, TIME or DATETIME values displayed (by default) contains always all important digits.

    Example:

    2015-10-14          will be displayed as 2015-10-14 (or default DATE format)
    2018-10-25 12:20:00 will be displayed as 2018-10-25 12:20
    1994-04-16 16       will be displayed as 1994-04-16 16
    

    The principle is simple.

    All digits being part of DATE will always be displayed as INTEGER part of float number. For TIME part, only significant part will be displayed as for DECIMAL part in float number. Naturally, for TIME type (only HH:MM:SS), the DATE part is never displayed.

    0 讨论(0)
  • 2020-11-29 01:03

    A DATE value per the SQL standard is YYYY-MM-DD. So even though Oracle stores the time information, my guess is that they're displaying the value in a way that is compatible with the SQL standard. In the standard, there is the TIMESTAMP data type that includes date and time info.

    0 讨论(0)
  • 2020-11-29 01:06

    It's never wise to rely on defaults being set to a particular value, IMHO, whether it's for date formats, currency formats, optimiser modes or whatever. You should always set the value of date format that you need, in the server, the client, or the application.

    In particular, never rely on defaults when converting date or numeric data types for display purposes, because a single change to the database can break your application. Always use an explicit conversion format. For years I worked on Oracle systems where the out of the box default date display format was MM/DD/RR, which drove me nuts but at least forced me to always use an explicit conversion.

    0 讨论(0)
  • 2020-11-29 01:08

    This is a "problem" on the client side, not really an Oracle problem.

    It's the client application which formats and displays the date this way.

    In your case it's SQL*Plus which does this formatting.
    Other SQL clients have other defaults.

    0 讨论(0)
  • 2020-11-29 01:08

    I'm not an Oracle user (well, lately anyhow), BUT...

    In most databases (and in precise language), a date doesn't include a time. Having a date doesn't imply that you are denoting a specific second on that date. Generally if you want a time as well as a date, that's called a timestamp.

    0 讨论(0)
提交回复
热议问题