oracle varchar to number

ぐ巨炮叔叔 提交于 2019-11-28 02:25:57

问题


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'

回答1:


You have to use the TO_NUMBER function:

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



回答2:


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);



回答3:


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




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/1154612/oracle-varchar-to-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!