oracle oracle中如何将整数转换为十进制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16457301/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:01:13  来源:igfitidea点击:

How to Convert integer to decimal in oracle

oracleintegerdecimal

提问by End.Game

how can i convert a integer to decimal in oracle? Is there any function like TO_CHAR? I need to put this function on a where clause. Thanks

oracle中如何将整数转换为小数?有没有像 TO_CHAR 这样的函数?我需要将此函数放在 where 子句上。谢谢

SELECT IDDS,
       ID
FROM   T_TABLEONE
WHERE  CAST(ID as DECIMAL)='1,301131832E19';

采纳答案by David Aldridge

If you apply a function to the column then you can run the risks of:

如果对列应用函数,则可能会面临以下风险:

  1. being unable to use a regular index on that column
  2. obscuring the expected cardinality of the result set, which can cause query optimisation problems.
  1. 无法在该列上使用常规索引
  2. 模糊结果集的预期基数,这可能会导致查询优化问题。

So it's generally a bad practice, and you'd do better to cast your literal to the same type as the column, in this case using to_number().

所以这通常是一个不好的做法,你最好将你的文字转换为与列相同的类型,在这种情况下使用 to_number()。

However in this case I'm surprised that it's necessary, as Oracle's type conversion in recent releases should be able to cope with comparing an integer column to a number expressed in scientific notation: http://sqlfiddle.com/#!4/336d3/8

但是,在这种情况下,我很惊讶这是必要的,因为最近版本中的 Oracle 类型转换应该能够处理将整数列与以科学记数法表示的数字进行比较:http: //sqlfiddle.com/#!4/336d3 /8

回答by Mitch Wheat

Use CAST:

使用CAST

CAST(myInt AS DECIMAL)