加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle中date类型的比较

发布时间:2020-12-12 16:23:11 所属栏目:百科 来源:网络整理
导读:字段dtCreatDates 在oracle中为DATE类型,java类中为DATE类型. private Date dtCreatDate; 现在从条件框返回一个格式为"2015-06-03"的String类型的字符串,在service中用sql语句进行日期的条件查询. 那么需要将string类型转换为日期类型,再与日期类型进行比较.

字段dtCreatDates 在oracle中为DATE类型,java类中为DATE类型.


private Date dtCreatDate;


现在从条件框返回一个格式为"2015-06-03"的String类型的字符串,在service中用sql语句进行日期的条件查询.


那么需要将string类型转换为日期类型,再与日期类型进行比较...


代码如下:


Service:
String hql = "SELECT COUNT(*) FROM Instructions  ";
                hql =hql+where;

String strStartDate=ParamUtil.getString(request,"strStartDate","");//格式为:2010-05-03
	String strEndDate=ParamUtil.getString(request,"strEndDate","");//格式为:2016-06-01
 	
	if(!strStartDate.equals("")){
		 tWhere+=" and dtCreatDate>=to_date('"+strStartDate+" 00:00:00','yyyy-mm-dd hh24:mi:ss')";
	}
	if(!strEndDate.equals("")){
		 tWhere+=" and dtCreatDate<=to_date('"+strEndDate+" 23:59:59','yyyy-mm-dd hh24:mi:ss')";
	}
int count = objSvr.getCount(tWhere);


打印的语句如下:

WHERE intVirDel<>1  and dtCreatDate>=to_date('2016-06-01 00:00:00','yyyy-mm-dd hh24:mi:ss') and dtCreatDate<=to_date('2016-06-24 23:59:59','yyyy-mm-dd hh24:mi:ss')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读