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

后端 未结 12 2503
温柔的废话
温柔的废话 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:27

    The biggest PITA of Oracle is that is does not have a default date format!

    In your installation of Oracle the combination of Locales and install options has picked (the very sensible!) YYYY-MM-DD as the format for outputting dates. Another installation could have picked "DD/MM/YYYY" or "YYYY/DD/MM".

    If you want your SQL to be portable to another Oracle site I would recommend you always wrap a TO_CHAR(datecol,'YYYY-MM-DD') or similar function around each date column your SQL or alternativly set the defualt format immediatly after you connect with

    ALTER SESSION 
    SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS'; 
    

    or similar.

提交回复
热议问题