This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selecting a DISTINCT date from a Timestamp column

 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Is there any Oracle function using which I can select a DISTINCE date from a Timestamp column? I have a column in one of my table that is a Timestamp and I want to select DISTINCT dates from it, but it is returning me also the results with the same date just because of the different associated time on the same date. Please help!
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Got it, I used a trunc function to get this done.
 
sowmy raj
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "date" in this question?

Are you talking about an Oracle DATE data type-- a structure that has a day and a time component with a precision of a second? Or are you talking about a date in terms of the combination of a day, month, and year with no time component?

You can apply a TRUNC to the timestamp to truncate the timestamp to whatever precision you would like, i.e.


SELECT DISTINCT TRUNC( <<timestamp>>, 'HH24' )
FROM dual;

SELECT DISTINCT TRUNC( <<timestamp>>, 'SS' )
FROM dual

SELECT DISTINCT TRUNC( <<timestamp>>, 'DD' )
FROM dual



give you the distinct Oracle dates with a granularity of hours, seconds, and days respectively.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic