Chinaunix

标题: oracle9 number小数精度控制 [打印本页]

作者: chuchadf    时间: 2007-06-13 15:06
标题: oracle9 number小数精度控制
在ora9中中,如何把字符串'54321.00'转换为number(9,2)类型,保留2位小数呢?
我试了cast,to_number都不行,转换出来不能把2位小数保留的。

select cast('54321.00' as number(9,2)) from dual;

CAST('54321.00'ASNUMBER(9,2))
-----------------------------
                        54321

各位帮忙解决下啊,
多谢
作者: goodhawk    时间: 2007-06-13 17:16
TRIM(TO_CHAR(CAST ('54321.00' AS NUMBER (9, 2)),'999999999.99'))

ps: oracle这样的处理方式不好。
作者: doni    时间: 2007-06-13 17:31
to_number('54321,00')即可,select出来是54321只是显示的问题,insert到number(9,2)的字段里就是9,2的
作者: leetz    时间: 2007-07-27 15:42
这不是显示问题,是版本问题

-----------------------------------------------
Connected to Oracle9i Release 9.2.0.1.0
Connected as erpsystem

SQL> create or replace view v_test as select cast(1 as number(1)) id from dual
  2  /

View created

SQL> desc v_test
Name Type   Nullable Default Comments
---- ------ -------- ------- --------
ID   NUMBER Y  

-----------------------------------------------
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as erpsystem

SQL> create or replace view v_test as select cast(1 as number(1)) id from dual
  2  /

View created

SQL> desc v_test
Name Type      Nullable Default Comments
---- --------- -------- ------- --------
ID   NUMBER(1) Y




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2