Oracle. How to output date and time?

前端 未结 5 1208
萌比男神i
萌比男神i 2020-12-09 18:50

My Visit table is the following:

insert into Visit
values(12, to_date(\'19-JUN-13\', \'dd-mon-yy\'), to_date(\'19-JUN-13 12:00 A.M.\' , \'dd-mon-yy hh:mi A.M         


        
5条回答
  •  北海茫月
    2020-12-09 19:46

    You're relying on implicit date conversion, which is using your (session-dependent, but maybe inherited from the DB default) NLS_DATE_FORMAT setting - in this case that seems to be DD-MON-RR.

    You can use to_char to specify the format, e.g.:

    select to_char(actualarrivaltime, 'DD-MON-YYYY HH:M:SS PM') from ..
    

    The datetime format models are described in the documentation.

    In general it's better to never rely on implcit conversions. Even if you get what you expect now, they can be session-specific so another user in another client ,ight see something different. This can cause failures as well as just look wrong. Always specify date and number formats, using to_date, to_char, to_timestamp etc.

提交回复
热议问题