oracle 甲骨文数转十进制

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

Oracle number to decimal

oracleplsql

提问by Remya

How I can select a number value in decimal, just like 12 to 12.00, without using to_char in oracle?

如何在不使用 oracle 中的 to_char 的情况下选择十进制的数值,就像 12 到 12.00 一样?

采纳答案by Mark Bowytz

If you're using SQL*Plus, you can format the output by changing the column format:

如果您使用 SQL*Plus,您可以通过更改列格式来格式化输出:

SQL> desc temp
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER
 FIELD1                                             VARCHAR2(100)
 FIELD2                                             VARCHAR2(100)

SQL> select * from temp;

        ID FIELD1     FIELD2
---------- ---------- ----------
         1 hello      yyyy
         2 hello      yyyy

SQL> col id format 999.99
SQL> select * from temp;

     ID FIELD1     FIELD2
------- ---------- ----------
   1.00 hello      yyyy
   2.00 hello      yyyy

回答by Shailesh

You can use

您可以使用

Select To_char(ID,'9990.99') from temp

0 is must for the formatting. If you want 0.00value (eg:0.10,0.06) you have to put 0 inside the format without 0 it will look like this .00(eg:.10,.06). Check it out here

0 是必须的格式。如果您想要0.00值(例如:0.10,0.06),您必须将 0 放在没有 0 的格式中,它看起来像这样 .00(例如:.10,.06)。在这里查看

Without 0

没有 0

Select To_char(0,'999.99') from Dual

With 0

与 0

Select To_char(0,'9990.99') from Dual

回答by btilly

Cast it to NUMBER(9, 2)(the 9 is arbitrary, use something else if you want) and it will be in that form.

将它投射到NUMBER(9, 2)(9 是任意的,如果你想使用其他的东西),它就会是那种形式。

However note that once you put it into your application, the representation is up to whatever language that uses. If it represents that data type as a float, you'll get a float and it will no longer have the format you want. In that case you are better off not formatting it until the number is outside of the database.

但是请注意,一旦将其放入应用程序中,表示取决于使用的任何语言。如果它将该数据类型表示为浮点数,您将得到一个浮点数,并且不再具有您想要的格式。在这种情况下,最好不要格式化它,直到数字在数据库之外。