Clarity

SQL Tip: TRUNC vs TO_CHAR 

Nov 28, 2017 11:08 AM

Sometimes you need to compare dates in SQL but you don't want the hours and minutes to count. 

 

2017-01-01 08:30:11

 

I have seen quite some SQL code using the TO_CHAR function: TO_CHAR(date, 'yyyy-mm-dd'). But this is quite a performance expansive function. Especially if used a lot in the query.

 

You can use another (much more performant function) : TRUNC

 

TRUNC(2017-01-01 08:30:11) will give: 2017-01-01 00:00:00 as a result and will allow you to compare dates independently from the hours and minutes as well.

 

Hope this helps,

Statistics
0 Favorited
2 Views
0 Files
0 Shares
0 Downloads

Related Entries and Links

No Related Resource entered.