2009-07-20 14 views
26

Jak przekonwertować wartość oracle varchar do numeruoracle varchar do numeru

np

table - exception 
exception_value 555 where exception_value is a varchar type 

Chciałbym przetestować wartość exception_value kolumnie

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

Odpowiedz

1

wybierz TO_NUMBER (exception_value) z wyjątku gdzie to_numer (wartość_wyjątku) = 105

34

You hav e używać TO_NUMBER funkcję:

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

Ponieważ kolumna jest typu VARCHAR, należy przekształcić parametr wejściowy na ciąg zamiast konwersji wartość kolumny na numer:

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

jeśli chce sformatowany numer użyj

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

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

Wynik 123,00

0

Ja testowałem sugerowanych rozwiązań, powinny one wszystkie prace:

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

=> dostarcza jeden manekin rząd

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

=> wynik pusty

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

=> dostarcza jeden manekin wiersz

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

=> pusty wynik