1、如果 oracle 數據庫中存的 time 是類型是 varchar2 ,傳入參數也是字符串。
① select * from table where time < #{time}
或者是 ② select * from table where time ≤ #{time}
在或者是 ③ select * from table where time <![CDATA[ < ]] #{time} |
這3條sql的意義都一樣,但是<![CDATA[ ]]中的字符 會保證 [] 中的字符不會被轉義,xml中建議使用②③。
2、比較時間字符串格式 和 時間格式。如果篩選條件對帶索引字段的進行格式轉換,索引會失效。
轉化成相同類型的比較,統一格式。
使用to_char(prarm ,"yyyy-mm-dd 24HH:mi:ss") 轉成字符串比較
select * from to_char(createTime , 'yyyy-mm-dd 24HH:mi:ss') < "2020-10-08 23:23:23" ; |
使用to_date(prarm ,"yyyy-mm-dd 24HH:mi:ss") 轉成時間比較
select * from createTime < to_date('2020-10-08 23:23:23', 'yyyy-mm-dd 24HH:mi:ss') ; |
3、關於to_date()函數
在oracle中建有date類型的字段,插入可以采取如下方法:
如果是小時為:1-12采取如下格式:yyyy-mm-dd HH:MI:SS
insert into test values(to_date('2020-10-08 23:23:23','yyyy-mm-dd HH:MI:SS')) ; |
如果是小時為:1-24采取如下格式:yyyy-mm-dd HH24:MI:SS
insert into test values(to_date('2020-10-08 23:23:23','yyyy-mm-dd HH24:MI:SS')) ; |
insert into table(createTime) value(to_date('2020-10-08','yyyy-mm-dd')) ;
insert into table(createTime) value(to_date('2020-10-08 23:23:23','yyyy-mm-dd hh24:mi:ss')) ;
insert into table(createTime) value(to_date('20201008','yyyymmdd')) ;
insert into table(createTime) value(to_date('20201008232323','yyyymmddhh24miss')) ; |