Oracle是否为Number数据类型存储尾随零? [英] Does Oracle store trailing zeroes for Number data type?

查看:97
本文介绍了Oracle是否为Number数据类型存储尾随零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将数字值存储在表中并在SQL Developer中查询该表时,它没有显示Number数据类型的尾随零.

When i am storing numeric values in a table and querying that table in SQL Developer, it is not showing trailing zeroes for Number data type.

create table decimal_test(decimal_field number(*,10));

insert into decimal_test(decimal_field) values(10);
insert into decimal_test(decimal_field) values(10.11);
insert into decimal_test(decimal_field) values(10.100);
insert into decimal_test(decimal_field) values(10.00);

select * from decimal_test;

结果是

10
10.11
10.1
10

这些值是从Java代码处理的.在这种情况下,我使用BigDecimal存储值.

These values are processed from java code. In this case i am using BigDecimal to store the value.

在保存到DB之前,如果我有BigDecimal(10.00),则在保存之后,从DB返回的值是BigDecimal(10). BigDecimal中的Equals方法失败,因为缩放比例已更改.

Before saving to DB, if i have BigDecimal(10.00), after saving, the value returned from DB is BigDecimal(10). Equals method in BigDecimal fails because the scale is changed.

并且我的十进制精度不是恒定的.用户可以设置BigDecimal(10.00)或BigDecimal (10.000)等.因此,值需要按原样存储在DB中.

And i the decimal precision is not constant. User can set BigDecimal(10.00) or BigDecimal(10.000) etc. Because of this, value needs to stored in DB as it is.

有什么方法可以将尾随零存储在oracle中吗?

Is there any way to store the trailing zeros in oracle?

推荐答案

尾随零的存在是一个 display 问题,而不是存储问题.尾随的零并不重要,并且只要 values 正确,数字的内部格式就无关紧要. 1010.00000之间没有值差异.

The existence of the trailing zeros is a display issue, not a storage issue. The trailing zeros are not significant, and anyway the internal format of the numbers is immaterial as long as the values are correct. There is no value difference between 10 and 10.00000.

如果需要尾随零,可以在转换显示值时始终使用格式.例如:

If you need trailing zeros you can always use formatting when converting the values for display. For example:

System.out.printf("%10.4d\n", decimalValue);

如果问题出在比例尺上,则可以 设置 ,将比例尺设置为适当的值,然后再进行比较.

If the problem is differences in scale, you can set the scale to the appropriate value before comparing.

这篇关于Oracle是否为Number数据类型存储尾随零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆