4

在 Oracle 中,如果列类型为 datetime ,如何进行此日期比较?我想保留字符串格式 'MM/dd/yyyy' 。

这个怎么做 ?

谢谢

select * from my_tbl
where mycol >= '07/11/2012'
4

1 回答 1

7

假设该日期表示 7 月 11 日:

select * 
from my_tbl
where mycol >= to_date('07/11/2012', 'MM/DD/YYYY');

如果该日期应为 11 月 7 日:

select * 
from my_tbl
where mycol >= to_date('07/11/2012', 'DD/MM/YYYY');

根据您填写 mycol 值的方式,您可能还想去掉时间部分:

select * 
from my_tbl
where trunc(mycol) >= to_date('07/11/2012', 'DD/MM/YYYY');
于 2012-07-12T20:37:49.363 回答