问题:
I am trying to get the number of days between SYSDATE and a column in one of my tables without using TRUNC since I need the timestamp to be included within the subtraction....
可以将文章内容翻译成中文,广告屏蔽插件会导致该功能失效:
问题:
I am trying to get the number of days between SYSDATE
and a column in one of my tables without using TRUNC since I need the timestamp to be included within the subtraction.
I am trying to achieve something similar to the code below but without using TRUNC
select * from table_name where trunc(sysdate) - trunc(column_name) > 60;
Note that column_name
is a Timestamp not a Date.
回答1:
Use an INTERVAL datatype to define an interval. to_dsinterval()
converts a string of the format `DD HH24:MI:SS' to an interval, in this case of exactly sixty days:
select * from table_name
where column_name < sysdate - to_dsinterval('60 0:0:0');
回答2:
You could use:
select * from table_name where column_name <= sysdate - 60;
or:
SELECT * FROM table_name WHERE column_name < sysdate - interval '60' day;
回答3:
Why don't you try select req_columns from MyTable where sysdate - column > 60
.
You can try below query if one of the column is timestamp.
select * from Mytable where sysdate - to_date(to_char(colTimeStamp, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS') > 60