你能看出这个查询有什么问题吗?

时间:2014-02-28 16:03:50

标签: sql oracle

我在Grails 2.2.4开发一个应用程序并使用Groovy,我有这部分代码:

def str2= """select to_number(to_date(NEXTRUNTIME,'DD-MON-YYYY') - to_date(LASTRUNTIME,'DD-MON-YYYY')) as DAYS, SUBSTR(to_CHAR(NEXTRUNTIME,'DD-MON-YYYY HH24:MI:SS'),13,8)as Hour from v8_recurtimeevent WHERE to_date(NEXTRUNTIME,'DD-MON-YYYY') != to_date(LASTRUNTIME,'DD-MON-YYYY') AND EVENT_UUID='000001112eae40e3-0000-b517-0a40246b';"""
 sql.eachRow(str2)
 {
     x.date="Days:"+"${it.Days}".toString()+" and hour: "+"${it.Hour}"
 }

当我执行它时,我得到了这个错误。你能看出发生了什么事吗?

  

URI
  / JobMigrator /职吧/ tableJobs
  类
  java.sql.SQLSyntaxErrorException
  消息
  ORA-00911:无效字符

1 个答案:

答案 0 :(得分:2)

def str2= "select to_number(TRUNC(NEXTRUNTIME) -
                          TRUNC(LASTRUNTIME)) as DAYS,
                  SUBSTR(to_CHAR(NEXTRUNTIME,'DD-MON-YYYY HH24:MI:SS'),13,8)as Hour
           from v8_recurtimeevent
           WHERE TRUNC(NEXTRUNTIME) != TRUNC(LASTRUNTIME)
             AND EVENT_UUID='000001112eae40e3-0000-b517-0a40246b'"

此外,TRUNC()就是您所需要的!忽略日期中的时间元素!