Oracle's default DATE format

前端 未结 4 1670
南旧
南旧 2020-11-28 12:55

First time using Oracle SQL (I\'m used to MySQL). I\'m finding conflicting info on what the default date format is. After several attempts having to use TO_DATE with my IN

4条回答
  •  半阙折子戏
    2020-11-28 13:31

    Oracle, as well as other databases, allows you to set the default format. Out of the box, the format is (typically) DD-MON-RR, where "RR" refers to a two-digit year. This is a pretty lousy format, from the perspective of ambiguity (two digit year?) and internationalization (for what countries is that actually the default?). But Oracle has been around a long, long time.

    Standard formats are also defined by ISO, the International Standards Organization. They settled on something more like YYYY-MM-DD. Actually, the hyphens are optional, but I think they make the date much more readable.

    Oracle accepts constants in this format, if you use DATE:

    select DATE '2018-01-25'
    

    This is very handy. First, it is nice to support reasonable standards. Second, the code is safe, regardless of internationalization settings. Oracle documentation of course covers this in detail; here is one place to start.

提交回复
热议问题