mysql中的substr()函数和hibernate的substr()参数都一样,就是含义有所不同。

用法:

substr(string string,num start,num length);

string为字符串;

start为起始位置;

length为长度。

区别:

mysql中的start是从1开始的,而hibernate中的start是从0开始的。

最常用在时间时间搜索上如

2016-09-01 19:02:19到2016-09-20 19:02:19

想搜索当天的如1号到1号的就要写成

if (sdate != null && !"".equals(sdate)) {
sql += " and substr(" + timetype + ",1,10)>='" + sdate + "'";
}
if (edate != null && !"".equals(edate)) {
sql += " and substr(" + timetype + ",1,10)<='" + edate + "'";
}

mysql中的substr()函数

这里timetype 代表按什么方式搜并且取值为1到10位sdate为开始时间edate为结束时间数据库中的时间为2016-09-01 19:02:19我们现在只需要前面10位如果不这样你无法搜索当天的数据如14号当天的数据

 

相关文章:

  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-03-04
相关资源
相似解决方案