某个表里面有begindate、enddate两个字段(开始日期和结束日期),char(10)的格式(比如:2010-04-29)。
我想写个SQL可以查出sysdate在begindate和enddate之间的记录。sysdate可以直接和char(10)的类型比较吗?比如:
select table1.* from table1
where tochar(sysdate,'yyyy-mm-dd') between begindate and enddate;
我想写个SQL可以查出sysdate在begindate和enddate之间的记录。sysdate可以直接和char(10)的类型比较吗?比如:
select table1.* from table1
where tochar(sysdate,'yyyy-mm-dd') between begindate and enddate;
from t
where begindate >= to_char(trunc(sysdate), 'yyyy-mm-dd')
and enddate < to_char(trunc(sysdate) + 1, 'yyyy-mm-dd')
where to_char(sysdate,'yyyy-mm-dd')>=begindate and to_char(sysdate,'yyyy-mm-dd')<=enddate
你的写法是用不上索引的(除非另建函数索引),所以最
好不要在字段上加函数计算,推荐1楼的写法。
where to_char(sysdate,'yyyy-mm-dd') between begindate and enddate;