2011-10-22 44 views
-1

這個請求按預期工作:ORA-00911錯誤與to_date函數

select dit_in.id data_item_in, dit_out.id data_item_out, alg.id algo_id 

from algorithm_run arun 

join algorithm_run_of arof on 
arof.algorithm_run_id = arun.id 

join algorithm_run_input arin on 
arin.algorithm_run_id = arun.id 

join data_item dit_in on 
dit_in.id = arin.data_item_id 

join algorithm alg on 
alg.id = arof.algorithm_id 

join algorithm_run_output arout on 
arout.algorithm_run_id = arun.id 

join data_item dit_out on 
dit_out.id = arout.data_item_id 

where alg.id in (182,183,143,162,125,222) 

不幸的是,我得到一個錯誤,當我在結尾處加上:

and arun.start_time >= to_date(’01/jun/2011’,’dd/mm/yyyy’) 
and arun.start_time < to_date(’01/jul/2011’,’dd/mm/yyyy') 

我使用一個Web界面,該錯誤消息是:

警告:oci_execute()[function.oci-執行]:ORA-00911:在/ opt/CSW/apache2的/股無效字符/ htdocs中/ DAE /位點/默認/模塊/ d請注意:oci_fetch_row()[function.oci-fetch-row]:ORA-24374:在獲取或執行之前定義未完成並在/ opt/csw/apache2/share中獲取/htdocs/DAE/sites/default/modules/daedatabase/daedatabase_db.inc上線852

+5

說明「開始失敗」。如果它給出錯誤消息,請發佈錯誤消息。如果它返回錯誤的數據,請描述應返回的數據與返回的數據。 –

+0

用錯誤消息編輯的帖子。 –

回答

2

由於Phil points out,您的字符串包裹在兩個不同的引號中。看起來你主要使用來自文字處理器的花哨引號。這是一個問題,因爲Oracle期望純ASCII撇號(ASCII 39)。

這當然可以解釋爲什麼你會得到一個ORA-00911錯誤。

要解決這個問題,你只需要用'替換所有的

爲避免將來出現這種情況,在編寫代碼時應該使用文本編輯器或IDE。

+0

非常感謝。我以pdf的形式從一篇研究論文中查詢,但是不夠細心。 –

5

試試這個:

and arun.start_time >= to_date(’01/06/2011’,’dd/mm/yyyy’) 
and arun.start_time < to_date(’01/07/2011’,’dd/mm/yyyy’) 

and arun.start_time >= to_date(’01/jun/2011’,’dd/mon/yyyy’) 
and arun.start_time < to_date(’01/jul/2011’,’dd/mon/yyyy’) 

問題是您的日期字符串(01/Jun/2011)與格式說明符(dd/mm/yyyy)不匹配。您需要更改日期或說明符,如上例所示。

+0

沒關係。 JUN的自動評估值爲06.當我放置06時,我仍然得到相同的錯誤。 –

5
and arun.start_time < to_date(’01/jul/2011’,’dd/mm/yyyy') 

我在最後一位看到兩種不同類型的引號字符嗎?單引號和反引號?或者這只是剪切/粘貼或翻譯問題?