關于日期函數TO_TIMESTAMP
拓展:
date類型是Oracle常用的日期型變量,時間間隔是秒。兩個日期型相減得到是兩個時間的間隔,注意單位是“天”。
timestamp是DATE類型的擴展,可以精確到小數秒(fractional_seconds_precision),可以是?0to9,缺省是6。兩個timestamp相減的話,不能直接的得到天數,而是得到,多少天,多少小時,多少秒等。
使用TO_TIMESTAMP函數:
select
distinct hiui.salesman_id as salesmanId,
hui.user_name as salesmanName,
hui.user_phone as salesmanPhone,
hiui.class_id as classId,
hiui.department_id as departmentId,
get_affiliaction_name(hiui.class_id, hiui.department_id) as affiliactionName
from hz_invited_user_info as hiui
inner join hz_user_info as hui on hui.user_id = hiui.salesman_id
where
to_timestamp('2018-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss') <= hiui.create_time
and to_timestamp('2019-05-28 00:00:00','yyyy-mm-dd hh24:mi:ss') >= hiui.create_time
時間: 0.949s? ? ? ? ? ??時間: 0.973s? ? ? ? ? ? ? ?時間: 0.783s
不使用:
select
distinct hiui.salesman_id as salesmanId,
hui.user_name as salesmanName,
hui.user_phone as salesmanPhone,
hiui.class_id as classId,
hiui.department_id as departmentId,
get_affiliaction_name(hiui.class_id, hiui.department_id) as affiliactionName
from hz_invited_user_info as hiui
inner join hz_user_info as hui on hui.user_id = hiui.salesman_id
where
'2018-01-01 00:00:00' <= hiui.create_time
and '2019-05-26 00:00:00' >= hiui.create_time
時間: 0.79s? ? ? ? ? ? ?時間: 0.743s? ? ? ? ? ? ? ? ? ?時間: 0.747s
兩者分別執行了3次,發現不使用效率更高,因為在sql執行的時候,會自動把時間字符串轉換成時間戳。但是使用效率也區別不是很明顯,可能是小數據的原因。