select * from tablename where columnname between to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd') and to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd')
sysdate取'yyyy-mm-dd'時候,系統默認的時分秒就是00:00:00 或者換一種寫法就是 select * from tablename where to_char(columnname,'yyyy-mm-dd hh24:mi:ss') between to_char(sysdate-1,'yyyy-mm-dd') || ' 00:00:00' and to_char(sysdate,'yyyy-mm-dd') || ' 00:00:00'還是第一種比較好.有columnname的index還能用的上
select a.* between to_date(to_char(sysdate-1,'yyyy-mm-dd')||' 00:00:00','yyyy-mm-dd hh24:mi ss') and to_date(to_char(sysdate,'yyyy-mm-dd')||' 00:00:00','yyyy-mm-dd hh24:mi ss')
select a.* between to_date(to_char(sysdate-1,'yyyy-mm-dd')||' 00:00:00','yyyy-mm-dd hh24:mi ss') and to_date(to_char(sysdate,'yyyy-mm-dd')||' 00:00:00','yyyy-mm-dd hh24:mi ss') 與 select * from tablename where columnname between to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd') and to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd') 是一樣的
between to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd') and to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd')
或者換一種寫法就是
select * from tablename where to_char(columnname,'yyyy-mm-dd hh24:mi:ss')
between to_char(sysdate-1,'yyyy-mm-dd') || ' 00:00:00' and to_char(sysdate,'yyyy-mm-dd') || ' 00:00:00'還是第一種比較好.有columnname的index還能用的上
與
select * from tablename where columnname
between to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd') and to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd')
是一樣的