GurunathKudalkar
GurunathKudalkar

Reputation: 1

use of trunc date in sql

can anyone explain me the working of trunc(date) function in oracle. my query is as below.

select trunc(tran_date) from tablename;

i have not passed any format type. If i compare the date present in table without having trunc(date) it will not give any output. and if compare date table with trunc(date) it will give me proper ouptut. please explain how it is working. and is there any replacement for trunc function as it is taking too much time.

Upvotes: 0

Views: 1075

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269553

trunc(tran_date) returns the date portion of the date column with no time component (which is midnight at the start of the day).

Despite its name, the date data type in Oracle includes the time. This is even more confusing because you sometimes do not see the time in the result set (depending on how you access the data).

The dates that you are comparing to have no time component. So, the comparison works with trunc(). But the time component on tran_date prevents the comparison from working without trunc().

Upvotes: 2

Related Questions