我需要查找特定时间范围内的行.
select *
from TableA
where startdate >= '12-01-2012 21:24:00'
and startdate <= '12-01-2012 21:25:33'
例如:我需要查找时间戳精度为秒的行.我如何做到这一点?
仅供参考:startdate
柱为TIMESTAMP
型.
我需要查找特定时间范围内的行.
select *
from TableA
where startdate >= '12-01-2012 21:24:00'
and startdate <= '12-01-2012 21:25:33'
例如:我需要查找时间戳精度为秒的行.我如何做到这一点?
仅供参考:startdate
柱为TIMESTAMP
型.
您需要使用to_timestamp()
将字符串转换为正确的timestamp
值:
to_timestamp('12-01-2012 21:24:00', 'dd-mm-yyyy hh24:mi:ss')
如果列的类型为DATE
(也支持秒),则需要使用至今
to_date('12-01-2012 21:24:00', 'dd-mm-yyyy hh24:mi:ss')
要使其达到where
状态,请使用以下方法:
select *
from TableA
where startdate >= to_timestamp('12-01-2012 21:24:00', 'dd-mm-yyyy hh24:mi:ss')
and startdate <= to_timestamp('12-01-2012 21:25:33', 'dd-mm-yyyy hh24:mi:ss')
对于类型为timestamp
的列,永远不需要使用to_timestamp()
.