2012-10-25 38 views
5

我有一個Date列,它實際上不是日期格式。 日期看起來像這樣:25/10/2012。 現在我必須比較兩個日期,但我不能找到一個模式來做到這一點,因爲格式是錯誤的。包含數字的Oracle SQL比較字符串,從0開始(零)

我曾嘗試是:

SELECT * 
    from PARAMETER 
    where NAME like 'Date_To' and SUBSTR(VALUE, 1, 2)<'25' 
    and SUBSTR(VALUE, 1, 2)>'05' 

我面臨的問題是,這部分:SUBSTR(PA_VALUE, 1, 2)>'05'不工作,因爲是數字0(零)盈。有沒有解決方案?

回答

2

嘗試像

SELECT * 
from PARAMETER 
where NAME like 'Date_To' 
and cast (SUBSTR(VALUE, 1, 2) as int) <cast ('25' as int) 
and cast (SUBSTR(VALUE, 1, 2) as int) > cast ('05' as int) 
+0

謝謝你這麼mutch! – Slim