I have the following in a SQL Server query which I have to convert to Oracle sp
DATEADD(dd, 0, DATEDIFF(dd, 0, DATEADD(ss, -L_LAST_TIME, TR.TR_DATETIME))) AS TRDATE,
Essentially you subtract L_LAST_TIME
seconds from TR_DATETIME
and then truncate the time part and keep only the date part.
You can divide intervals:
select trunc(TR.TR_DATETIME - interval L_LAST_TIME SECOND) AS TRDATE
or
select trunc(TR.TR_DATETIME - NUMTODSINTERVAL(L_LAST_TIME, 'SECOND')) AS TRDATE
We can do arithmetic with dates in Oracle.
select trunc(tr.tr_time - (l_last_time/86400)) as trdate
from tr
/
Dividing l_last_time
by 86400 turns a number of seconds into a fraction of day. Subtracing it from the tr_time
column gives you a new, earlier date. Truncating a date removes the time component.
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.