Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Trivia question re TO_DATE(SYSDATE)
laleonard_SpamBanana_AT_mindspring.com <laleonard_at_mindspring.com> wrote in
message news:7tlplr$92k$1_at_nnrp1.deja.com...
> I think I'm having a problem that I've traced to the use of TO_DATE
> (SYSDATE). I'm assuming that the correct syntax is just SYSDATE, but
> I'm curious (a) why does the former work at all, and (b) has anyone
> experienced problem doing that. TIA.
>
> Oh yeah, the problem is that occasionally the date inserted into the
> table ends up having its time set as 00:00:00.
The parameter of TO_DATE() function is CHAR or VARCHAR2 datatype.
Oracle implicitly converts sysdate into a VARCHAR2 string using TO_CHAR()
function, so the expression Oracle actually performed is
TO_DATE(TO_CHAR(SYSDATE)).
The default NLS_DATE_FORMAT is 'DD-MON-YY', that's why you lose
the time part of SYSDATE.
The correct usage is just SYSDATE, never use the detrimental TO_DATE(SYSDATE). Received on Sun Oct 10 1999 - 12:07:52 CDT