Reputation: 253
When I simplify the query, i.e.
SELECT TO_CHAR(MIN(I.INCIDENTID)) AS "Incident ID",
TRIM(TO_CHAR(I.CREATIONDATE,'DD-MON-YYYY')) AS "Creation Date"
FROM INCIDENT I
GROUP BY TRIM(TO_CHAR(I.CREATIONDATE,'DD-MON-YYYY'))
I get
But if I incorporate into my actual query for 164,000+ distinct rows, I get
But I expect this (only difference is, Creation Date must have proper Date format, not this complex string)
I am reading a date-time from an external Oracle Database, and have trimmed any extra spaces successfully with TRIM(I.CREATIONDATE)
.
I have verified this because my SQL query only displays distinct date values
However, TRIM(I.CREATIONDATE)
turns 2/26/2019 11:05:44 AM
into 26-FEB-19 11.05.43.925000 AM
, but I only want 26-FEB-19
When I apply regular expression to only get date, i.e. REGEXP_SUBSTR(TRIM(I.CREATIONDATE),'[^ ]+')
, it certainly outputs 26-FEB-19
, but somehow extra spaces are added because I get duplicate dates.
I have tried applying TRIM
a second time, i.e. TRIM(REGEXP_SUBSTR(TRIM(I.CREATIONDATE),'[^ ]+'))
, but I still get duplicates
Then I tried running regular expression first, then trim, but this does not work, i.e. TRIM(REGEXP_SUBSTR(I.CREATIONDATE,'[^ ]+'))
still gives duplicates.
Please assist
Upvotes: 0
Views: 833
Reputation: 1269873
I think you want trunc()
, not trim()
to remove the time component.
So try:
trunc(i.creationdate)
Or if you want the days in a particular string representation:
to_char(i.creationdate, 'YYYY-MM-DD')
Upvotes: 1