oracle varchar to number

2019-01-26 03:02发布

How do i convert a oracle varchar value to number

eg

table - exception
exception_value 555 where exception_value is a varchar type

I would like to test the value of exception_value column

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

5条回答
Deceive 欺骗
2楼-- · 2019-01-26 03:24

If you want formated number then use

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

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

Result 123.00

查看更多
太酷不给撩
3楼-- · 2019-01-26 03:39

You have to use the TO_NUMBER function:

select * from exception where exception_value = to_number('105')
查看更多
别忘想泡老子
4楼-- · 2019-01-26 03:43

Since the column is of type VARCHAR, you should convert the input parameter to a string rather than converting the column value to a number:

select * from exception where exception_value = to_char(105);
查看更多
一纸荒年 Trace。
5楼-- · 2019-01-26 03:47

select to_number(exception_value) from exception where to_number(exception_value) = 105

查看更多
放我归山
6楼-- · 2019-01-26 03:48

I have tested the suggested solutions, they should all work:

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

=> delivers one dummy row

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

=> empty result

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

=> delivers one dummy row

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

=> empty result

查看更多
登录 后发表回答