oracle demical,oracle jdbc DECIMAL and NUMERIC

8.3.11 DECIMAL and NUMERIC

The JDBC types DECIMAL and NUMERIC are very similar. They both represent fixed-precision decimal values. ame="1007716"> The corresponding sql types DECIMAL and NUMERIC are defined in sql-92 and are very widely implemented. These sql types take precision and scale parameters. The precision is the total number of decimal digits supported,and the scale is the number of decimal digits after the decimal point. For most DBMSs,the scale is less than or equal to the precision. So for example,the value "12.345" has a precision of 5 and a scale of 3,and the value ".11" has a precision of 2 and a scale of 2. JDBC requires that all DECIMAL and NUMERIC types support both a precision and a scale of at least 15.

The sole distinction between DECIMAL and NUMERIC is that the sql-92 specification requires that NUMERIC types be represented with exactly the specified precision,whereas for DECIMAL types,it allows an implementation to add additional precision beyond that specified when the type was created. Thus a column created with type NUMERIC(12,4) will always be represented with exactly 12 digits,whereas a column created with type DECIMAL(12,4) might be represented by some larger number of digits.

The recommended Java mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal. The java.math.BigDecimal type provides math operations to allow BigDecimal types to be added,subtracted,multiplied,and divided with other BigDecimal types,with integer types,and with floating point types.

The method recommended for retrieving DECIMAL and NUMERIC values is ResultSet.getBigDecimal. JDBC also allows access to these sql types as simple Strings or arrays of char. Thus,Java programmers can use getString to receive a DECIMAL or NUMERIC result. However,this makes the common case where DECIMAL or NUMERIC are used for currency values rather awkward,since it means that application writers have to perform math on strings. It is also possible to retrieve these sql types as any of the Java numeric types.

考虑用getString,这样也可以避免以后超出long的范围的问题。

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值