oracle varchar到数字

问题描述 投票:29回答:5

如何将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'
oracle numbers varchar
5个回答
37
投票

你必须使用TO_NUMBER函数:

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

12
投票

由于列的类型为VARCHAR,因此应将输入参数转换为字符串,而不是将列值转换为数字:

select * from exception where exception_value = to_char(105);

3
投票

如果您想要格式化的数字,请使用

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

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

结果123.00


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

=>空结果


1
投票

从异常中选择to_number(exception_value),其中to_number(exception_value)= 105

© www.soinside.com 2019 - 2024. All rights reserved.