2014-02-28 44 views
-3

林開發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}" 
      } 

當我執行它,我得到這個錯誤...能你看到什麼是metter?

URI
/JobMigrator /職吧/ tableJobs

java.sql.SQLSyntaxErrorException
消息
ORA-00911:無效字符

+2

第一個錯誤.'格式' –

+2

查詢字符串中的第二個錯誤「分號」! –

+0

Thak你,第二? –

回答

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()是你需要什麼!忽略日期中的時間元素!

+0

謝謝soooo多!!!!!!!它解決了!!!!!! –

+0

'to_number'也是多餘的;如果日期格式掩碼只是'HH24:MI:SS',則不需要'substr'。但你只能修復這麼多... * 8-) –

+0

我優化了它!謝謝! –