测试Oracle to_date函数 [英] Testing the Oracle to_date function

查看:237
本文介绍了测试Oracle to_date函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GORM编写一个Grails集成测试。



我想要做如下的事情:

 从统计
where stat_date = TO_DATE(:month_year,'MON-YYYY')

但是我获取以下错误:
$ b


java.sql.SQLException:意外的标记:语句中的TO_DATE [从统计信息中删除
,其中stat_date = TO_DATE(?,'MON-YYYY')]


我认为错误是由GORM使用的内存数据库引起的它H2?)不支持to_date函数。



有关如何编写删除SQL以便它在测试中和实时运行的任何想法? b
$ b

因为我只关心月份和年份,我认为我应该删除stat_date在给定月份的第一个和最后一个日期之间的记录。



任何一个人都可以想出更好的方法吗?

解决方案

支持TO_DATE,就是在 1.4.x路线图中。相反,您可以使用Oracle DB和H2中都存在的 EXTRACT 函数。


I'm writing an integration test in Grails using GORM.

I want to do something like the following:

delete from Statistic 
where stat_date = TO_DATE(:month_year, 'MON-YYYY')

But I get the following error:

java.sql.SQLException: Unexpected token: TO_DATE in statement [delete from statistics where stat_date=TO_DATE(?, 'MON-YYYY')]

I think the error is caused by the in memory database used by GORM (is it H2?) not supporting the to_date function.

Any ideas on how to write the delete SQL so that it works in a test and in live?

As I only really care about the Month and Year one thought I had would be to delete the records where the stat_date is between the first and last date of the given month.

Can any one think of a better way?

解决方案

Yes, H2 doesn't support TO_DATE, it's in 1.4.x roadmap. Instead you can use the EXTRACT function that exists both in Oracle DB and H2.

这篇关于测试Oracle to_date函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆