I have a TABLEA in below format (Updated Columns has Pacific TZ adjusted against UTC)
Status | Updated |
---|---|
Complete | 09/Mar/2021 08:27:30AM -1100 |
Apps Tasks | 04/Mar/2021 12:42:12AM -1100 |
Complete | 11/Mar/2021 09:27:30AM -1100 |
Complete | 12/Feb/2021 10:27:30AM -1100 |
I used below query and I get data as expected but it seems I am messing up date/Timestamp format as I am getting "ORA-01843: not a valid month" in Oracle Apex when I use below query to generate graph.I have been tweaking the query with to_date,to_char,trunc and combinations of TO_TIMESTAMP_TZ and NLS_LANGUAGE but seem to be going in circle.Any inputs would be appreciated if I am missing something in the formatting on the query?
select TRUNC(TO_TIMESTAMP_TZ(UPDATED),'MONTH') AS Month,COUNT(STATUS) AS "Complete" FROM TABLEA
where STATUS='Complete'
group by TRUNC(TO_TIMESTAMP_TZ(UPDATED), 'MONTH')
order by TRUNC(TO_TIMESTAMP_TZ(UPDATED), 'MONTH')
MONTH | Complete |
---|---|
02/01/2021 | 1 |
03/01/2021 | 2 |
Thanks
First, you should fix the data model to store date/time values using the appropriate time stamp which is not a string .
Second, I would return the results using dates:
select trunc(to_date(substr(update, 1, 11), 'DD/MMM/YYYY'), 'MON') as yyyymm,
count(*)
from t
group by trunc(to_date(substr(update, 1, 11), 'DD/MMM/YYYY'), 'MON');
You can, of course, format the first column however you want using to_char()
. However, I want to emphasize that your data and your code should be using date
s or timestamp
s.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.