oracle varchar 到数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1154612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
oracle varchar to number
提问by user141511
How do i convert a oracle varchar value to number
我如何将 oracle varchar 值转换为数字
eg
例如
table - exception
exception_value 555 where exception_value is a varchar type
I would like to test the value of exception_value column
我想测试 exception_value 列的值
select * from exception where exception_value = 105 instead of
select * from exception where exception_value = '105'
回答by FerranB
回答by Tony Andrews
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:
由于列是 VARCHAR 类型,您应该将输入参数转换为字符串,而不是将列值转换为数字:
select * from exception where exception_value = to_char(105);
回答by Arijit
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
结果 123.00
回答by Andreas L.
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
=> 空结果
回答by dpbradley
select to_number(exception_value) from exception where to_number(exception_value) = 105
从异常中选择 to_number(exception_value),其中 to_number(exception_value) = 105