change date format 'yyyy/mm/dd' to 'mm-dd-yyyy' in Oracle

后端 未结 2 1037
野趣味
野趣味 2020-12-04 03:51

I have inserted into a table in Oracle. My implementation without PLSQL would be:

SELECT to_date(\'1900-01-01\',\'YYYY-MM-DD\') + (rownum - 1) AS DT_CAL, 
          


        
2条回答
  •  暖寄归人
    2020-12-04 04:51

    The DATE data type does not have a format; Oracle stores it as either 7- or 8-bytes and it is not until it is passed to a client program (i.e. SQL/Plus, SQL Developer, Toad, Java, Python, etc) and that client program formats it according to whatever rules it has that the date gets a format.

    If you are using SQL/Plus or SQL Developer then it will use the NLS_DATE_FORMAT session parameter to format the date. You can change this using:

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

    (Be aware that this will only change the format in the current session and will not change it for any other sessions/users.)

    If you want to give the date a particular format then you will need to convert it to a string.

提交回复
热议问题