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