timestamp
Shahid, March 09, 2016 - 2:20 am UTC
Hi Connor,
Thanks you for you answer as it pinpointed me to the right direction. Not sure if another question arising from this can be asked or I have to open a new question?
March 09, 2016 - 5:45 am UTC
If its related, you can add it here
EXTENDED_TIMESTAMP
Al Khan, March 09, 2016 - 5:21 pm UTC
So after solving the time problem in my trigger the next issue is the daylight time. I have a query that is giving me the intended result as is for now, however when the daylight savings time start we are goign ahead one hour and this trigger will not work again because the time will be off by one hour again from systimetamp. I was under the impression from reading many other online posts that the EXTENDED_TIMESTAMP cloumn was made to handle the timezone/daylight issue? Maybe I understood it wrong. Is there a way that would allow me to handle daylight savings time automatically? I have tried many other online post and method exhaustively to no luck.
Query:
SELECT USERNAME, SYSTIMESTAMP, TO_CHAR(NEW_TIME (EXTENDED_TIMESTAMP -7/24,'MST', 'GMT'), 'DD-MON-YY HH24:MI:SS')
FROM DBA_AUDIT_TRAIL
WHERE EXTENDED_TIMESTAMP BETWEEN SYSTIMESTAMP -10/24/60 AND SYSTIMESTAMP
AND RETURNCODE IN (1017,1004,1005,28000)
AND USERNAME = failed_username
ORDER BY EXTENDED_TIMESTAMP DESC;
Result:
USERNAME SYSTIMESTAMP TO_CHAR(NEW_TIME(EXTENDED_T
--------- -------------------------------- ---------------------------
T1 09-MAR-16 10.04.17.873962 AM -07:00 09-MAR-16 10:03:58
T1 09-MAR-16 10.04.17.873962 AM -07:00 09-MAR-16 10:03:46
T1 09-MAR-16 10.04.17.873962 AM -07:00 09-MAR-16 10:03:36
T1 09-MAR-16 10.04.17.873962 AM -07:00 09-MAR-16 10:03:29
T1 09-MAR-16 10.04.17.873962 AM -07:00 09-MAR-16 10:03:23
March 10, 2016 - 2:47 am UTC
Well, you need to define what you are going to do for a start.
If the clock jumps forward 1 hour, then (by the wall clock definition) no-one has tried in the last 10mins.
Similarly, if the clock jumps back 1 hour, then are you planning on double-counting ? etc
It may well be the case that you just want to convert everything to UTC/GMT and work from there, but for those 2 hours of the entire year ... I'd be inclined not to bother.
EXTENDED_TIMESTAMP
Al Khan, March 10, 2016 - 12:28 am UTC
I thought I figured it out but not really,
When I run this query directly on the database I get the proper time returned by the EXTENDED_TIMESTAMP which is same as systimetamp of failed login attempt
SELECT USERNAME, to_char(SYSTIMESTAMP, 'DD-MON-YY HH24:MI:SS') AS TS, TO_CHAR(EXTENDED_TIMESTAMP, 'DD-MON-YYYY HH24:MI:SS TZH:TZM') AS E_TS
FROM DBA_AUDIT_TRAIL
WHERE EXTENDED_TIMESTAMP BETWEEN SYSTIMESTAMP -10/24/60 AND SYSTIMESTAMP
AND RETURNCODE IN (1017,1004,1005,28000)
AND USERNAME = 'T1'
ORDER BY EXTENDED_TIMESTAMP DESC;
USERNAME TS E_TS
------------------------------ --------------------------- ---------------------------------------------------------------------------
T1 09-MAR-16 17:23:18 09-MAR-16 05.23.13.771640 PM CANADA/MOUNTAIN
T1 09-MAR-16 17:23:18 09-MAR-16 05.23.10.202357 PM CANADA/MOUNTAIN
T1 09-MAR-16 17:23:18 09-MAR-16 05.22.59.113721 PM CANADA/MOUNTAIN
But via trigger the times does not match
USERNAME SYSTIMESTAMP EXTENDED_TIMESTAMP
------------------- ---------------------------------------------------------------------------
T1 09-MAR-16 05.23.10.261926 PM 05-MAR-16 03.55.41.890517 PM
T1 09-MAR-16 05.23.10.261926 PM 05-MAR-16 03.55.43.007400 PM
T1 09-MAR-16 05.23.10.261926 PM 05-MAR-16 03.55.44.661308 PM
T1 09-MAR-16 05.23.10.261926 PM 05-MAR-16 03.55.46.755995 PM
T1 09-MAR-16 05.23.10.261926 PM 05-MAR-16 03.55.51.296377 PM
T1 09-MAR-16 05.23.10.261926 PM 05-MAR-16 03.55.55.886834 PM
Again I thought the EXTENDED_TIMESTAMP column does not have to be provided hard coded offset value in order to take care of daylight savings.
EXTENDED_TIMESTAMP
Shahid Ali Khan, March 11, 2016 - 12:20 am UTC
Hi Connor,
I found a better way of dealing with daylight savings time. Since we know that timestamp/extended_timestamp column queried through the trigger will return GMT/UTC time then why not for the purpose of solving my problem bring the systimestamp column back to GMT/UTC and now both columns will return the same time. The SYS_EXTRACT_UTS(TimestampColumn) function will take this column to the GMT/UTC time.
Here's the query in my trigger that does this.
SELECT COUNT(*) INTO failed_login_attempts_count
FROM(SELECT USERNAME, SYS_EXTRACT_UTC(systimestamp), EXTENDED_TIMESTAMP
from DBA_AUDIT_TRAIL
where EXTENDED_TIMESTAMP between SYS_EXTRACT_UTC(systimestamp) -10/24/60 and SYS_EXTRACT_UTC(systimestamp)
and RETURNCODE in (1017,1004,1005,28000)
and USERNAME = failed_username);
Problem solved, thanks for your help.
March 11, 2016 - 1:17 am UTC
Glad we could help.