Another thread from today made me think of the basics of TRUNC function used for DATEs. I am confused about what it acutally does.
This is what Oracle Documenations says about TRUNC function without format (like 'DD-MON-YY')
"If you omit fmt, then date is truncated to the nearest day" (Oracle 10Gr2 SQL reference, B14200-02)
SQL> alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
Session altered.
Query 1.
SQL> SELECT SYSDATE FROM DUAL;
SYSDATE
--------------------
06-DEC-2007 14:22:01
Query 2.
SQL> SELECT TRUNC(SYSDATE) FROM DUAL;
TRUNC(SYSDATE)
--------------------
06-DEC-2007 00:00:00
I have three questions
1)Since it 2:22 pm , shouldn't the result of TRUNC(SYSDATE) ie Query 2. be 7-Dec-2007 ?
-
What difference does TRUNC function make in the code apart from setting the time to 00:00:00?
-
Is it safer to add TRUNC for DATEs in the code?
SQL> select sysdate-1 from dual;
SYSDATE-1
--------------------
05-DEC-2007 14:27:51
SQL> select trunc(sysdate) - 1 from dual;
TRUNC(SYSDATE)-1
--------------------
05-DEC-2007 00:00:00
Added third question
Message was edited by:
user609308