如何将oracle 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'
答案 0 :(得分:37)
您必须使用TO_NUMBER功能:
select * from exception where exception_value = to_number('105')
答案 1 :(得分:12)
由于列的类型为VARCHAR,因此应将输入参数转换为字符串,而不是将列值转换为数字:
select * from exception where exception_value = to_char(105);
答案 2 :(得分:3)
如果您想要格式化数字,请使用
SELECT TO_CHAR(number, 'fmt')
FROM DUAL;
SELECT TO_CHAR('123', 999.99)
FROM DUAL;
结果 123.00
答案 3 :(得分:2)
我测试了建议的解决方案,它们都应该有效:
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))
=>空结果
答案 4 :(得分:1)
从异常中选择to_number(exception_value),其中to_number(exception_value)= 105