2009-07-20 60 views
26

我如何轉換的Oracle VARCHAR值數點甲骨文VARCHAR到人數

table - exception 
exception_value 555 where exception_value is a varchar type 

我想考exception_value列

select * from exception where exception_value = 105 instead of 
select * from exception where exception_value = '105' 

回答

1

選擇TO_NUMBER的值(exception_value )從異常其中to_number(exception_value)= 105

34

你hav E可使用TO_NUMBER功能:

select * from exception where exception_value = to_number('105') 
10

由於列是VARCHAR類型的,你應該輸入參數轉換爲字符串,而不是列值轉換爲數字:

select * from exception where exception_value = to_char(105); 
3

如果您要格式化,然後用數

SELECT TO_CHAR(number, 'fmt') 
    FROM DUAL; 

SELECT TO_CHAR('123', 999.99) 
    FROM DUAL; 

結果 123.00

0

我已經測試了建議的解決方案,他們都應該工作:

select * from dual where (105 = to_number('105')) 

=>提供了一個虛擬的行

select * from dual where (10 = to_number('105')) 

=>空的結果

select * from dual where ('105' = to_char(105)) 

=>提供了一個虛擬行

select * from dual where ('105' = to_char(10)) 

=>空結果