1. 程式人生 > >oracle 字符串格式轉化 與 今天 /本周 /本月 查詢

oracle 字符串格式轉化 與 今天 /本周 /本月 查詢

acl col eat span edi number char ati subst

varchar(50) 轉化為時間格式對比:

// create_time,edit_time,格式為:varchar(50)  是否等於今天
select * from com_equ t where  t.use_org_id="+userOrgId+"  
and t.data_status=1  and TO_CHAR(t.create_time,YYYY-MM-DD)=TO_CHAR(SYSDATE,YYYY-MM-DD) or TO_CHAR(t.edit_time,YYYY-MM-DD)=TO_CHAR(SYSDATE,YYYY-MM-DD)

// create_time,edit_time,格式為:varchar(50)  是否等於某一天
select * from com_equ t where t.use_org_id="+userOrgId+" and t.data_status=1 and TO_CHAR(t.create_time,YYYY-MM-DD)=substr(2019-03-28,1,10) or TO_CHAR(t.edit_time,YYYY-MM-DD)=substr(2019-03-28,1,10)

查詢時間 今天 /本周 /本月 // 默認查詢今天 datatime 類型為varchar(50)

今天: (substr(d.datatime,1,10
))=TO_CHAR(SYSDATE,YYYY-MM-DD)

昨天:
(substr(d.datatime,1,10))=TO_CHAR(SYSDATE-1,‘YYYY-MM-DD‘)
本周:to_char(to_date(d.datatime,yyyy-mm-dd hh24:mi:ss),iw)=to_char(sysdate,iw) 

本月 :to_char(to_date(d.datatime,
yyyy-mm-dd hh24:mi:ss),mm)=to_char(sysdate,mm)

oracle 字符串格式轉化 與 今天 /本周 /本月 查詢