查詢條件中的截止日期問題

2021-10-18 02:24:52 字數 1095 閱讀 3323

介面輸入查詢條件顯示為:

經辦日期:2021-01-01 至 2021-01-28

生成的查詢條件合理的應為: 

where aae036 >=  to_date('2021-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')

and aae036 <=  to_date('2021-01-28 23:59:59', 'yyyy-mm-dd hh24:mi:ss')

常見的不合理情況

1、and aae036 <=  to_date('2021-01-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss')

如果aae036中時分秒不全為0,則無法查詢到截止日期當天的資料

2、where to_char(aae036,'yyyy-mm-dd') >=  '2021-01-01'

and to_char(aae036,'yyyy-mm-dd') <=  '2021-01-28'

如果aae036建了索引,to_char(aae036,'yyyy-mm-dd')是無法使用到索引的。

3、where aae036 >=  to_date('2021-01-01 00:00:00', 'yyyy-mm-dd hh:mi:ss')

and aae036 <=  to_date('2021-01-28 23:59:59', 'yyyy-mm-dd hh:mi:ss')

24小時制應為hh24,不應該是hh,在oracle中hh是12小時制。

4、where aae036 >=  to_date('2021-01-01 00:00:00', 'yyyy-mm-dd hh24:mm:ss')

and aae036 <=  to_date('2021-01-28 23:59:59', 'yyyy-mm-dd hh24:mm:ss')

分鐘是mi,不應該是mm,在oracle中mm是月

查詢剛訪問oracle的sql語句:

select * from v$sql where upper(sql_fulltext) like '%aae036 >=  to_date(%' 

and last_active_time > sysdate - 0.1;

獲取截止日期,包括對節假日 補班 雙休的處理

話說月光族的小明申請辦了一張信用卡,銀行規定,在受理成功後10個工作日 假設正常雙休不上班 之後將可領取信用卡。tags 小明的本次辦卡業務將在那天完成?分析需求 根據受理日期,由10個工作日這個限制條件,計算出截止日期即可,其中需要對正常雙休,國家法定節假日,補班等情況進行處理。解決方案 1 建立...

MySQL中以日期為查詢條件的方法

假如有個表product有個字段add time,它的資料型別為datetime,有人可能會這樣寫sql 如下 複製 select from product where add time 2013 01 12 對於這種語句,如果你儲存的格式是yy mm dd是這樣的,那麼ok,如果你儲存的格式是 2...

MySQL中以日期為查詢條件的方法

1.儲存的格式是yy mm dd型別時查詢 假如表product有欄位add time,它的資料型別為datetime,寫sql如下 如下 複製 select from product where add time 2019 01 12 對於這種語句,適合儲存的格式是yy mm dd型別的 1.da...