gpt4 book ai didi

sql - 基于格式的 Oracle 日期时间比较

转载 作者:行者123 更新时间:2023-12-04 23:59:53 32 4
gpt4 key购买 nike

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

这该怎么做 ?

谢谢

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

最佳答案

假设该日期是 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');

关于sql - 基于格式的 Oracle 日期时间比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11460188/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com