1、从页面上获取的是字符创类型的日期
如:date = "2012-3-14"如下是SQL:
2、SQL
select t.a,t.b,count(*)
from 表名 t where
t.add_date >= to_timestamp(date 00:00:00.000000,'yyyy-mm-dd hh24:mi:ss.ff')
and t.add_date <= to_timestamp(date 23:59:59.999999,'yyyy-mm-dd hh24:mi:ss.ff')
group by t.a,t.b
上述sql经过Hibernate转换后为:
select t.a,t.b,count(*)
from 表名 t where
t.add_date >= to_timestamp(2012-03-14 00:00:00.000000,'yyyy-mm-dd hh24:mi:ss.ff')
and t.add_date <= to_timestamp(2012-03-14 23:59:59.999999,'yyyy-mm-dd hh24:mi:ss.ff')
group by t.a,t.b
然后报 “ Not all named parameters have been set” 错,
原因是:日期字符串需要加 ''
正确的sql为:
select t.a,t.b,count(*)
from 表名 t where
t.add_date >= to_timestamp('2012-03-14 00:00:00.000000','yyyy-mm-dd hh24:mi:ss.ff')
and t.add_date <= to_timestamp('2012-03-14 23:59:59.999999','yyyy-mm-dd hh24:mi:ss.ff')
group by t.a,t.b
如:date = "2012-3-14"如下是SQL:
2、SQL
select t.a,t.b,count(*)
from 表名 t where
t.add_date >= to_timestamp(date 00:00:00.000000,'yyyy-mm-dd hh24:mi:ss.ff')
and t.add_date <= to_timestamp(date 23:59:59.999999,'yyyy-mm-dd hh24:mi:ss.ff')
group by t.a,t.b
上述sql经过Hibernate转换后为:
select t.a,t.b,count(*)
from 表名 t where
t.add_date >= to_timestamp(2012-03-14 00:00:00.000000,'yyyy-mm-dd hh24:mi:ss.ff')
and t.add_date <= to_timestamp(2012-03-14 23:59:59.999999,'yyyy-mm-dd hh24:mi:ss.ff')
group by t.a,t.b
然后报 “ Not all named parameters have been set” 错,
原因是:日期字符串需要加 ''
正确的sql为:
select t.a,t.b,count(*)
from 表名 t where
t.add_date >= to_timestamp('2012-03-14 00:00:00.000000','yyyy-mm-dd hh24:mi:ss.ff')
and t.add_date <= to_timestamp('2012-03-14 23:59:59.999999','yyyy-mm-dd hh24:mi:ss.ff')
group by t.a,t.b