【问题标题】:oracle varchar to numberoracle varchar 转数字
【发布时间】:2017-12-18 23:28:59
【问题描述】:

如何将 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


    【解决方案1】:

    你必须使用TO_NUMBER函数:

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

    【讨论】:

      【解决方案2】:

      由于列是 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

        【讨论】:

          【解决方案4】:

          我已经测试了建议的解决方案,它们应该都可以工作:

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

          => 空结果

          【讨论】:

            【解决方案5】:

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

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2011-12-31
              • 2018-04-07
              • 1970-01-01
              • 1970-01-01
              • 2013-12-10
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多