【发布时间】:2012-01-08 21:26:43
【问题描述】:
我正在使用 grails/groovy,并且从我的控制器中我目前正在这样做以从包含日期时间字段的 Mysql 表中检索字段
SimpleDateFormat Sformat = new SimpleDateFormat("yyyy-MM-dd");
String format_datenow = Sformat.format(new Date());
String format_dateprevious = Sformat.format(new Date() -31);
String markerCalcQuery =
"select sum(trans_cnt) as t_cnt, location from map2_data where fdate between '"+format_dateprevious+"' and '"+format_dateprevious+"' and res_id = "+res_id+" group by map2_data.location";
res_row=gurculsql.rows(markerCalcQuery);
上述查询在 Oracle11g 上失败并出现错误
ORA-01843:月份无效。
我感觉的错误是因为 MySQL 以这种格式存储日期:2011-12-28 02:58:26 而 Oracle 存储日期是这样的:28-DEC-11 02.58.26.455000000 PM
如何使代码通用化,一种方法是使 Oracle 中的数据库以我认为处理此问题的相同格式而不是从代码中存储日期。如果是,如何更改 Oracle 数据库中的日期格式?
我能否在 grails 域类中为 map2_data 指定格式,这样无论它是什么数据库,我们都将拥有相同格式的日期时间。
【问题讨论】:
标签: oracle datetime grails groovy