oracle 字符串格式转化 与 今天 /本周 /本月 查询

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')
原文地址:https://www.cnblogs.com/xkoko/p/10616844.html