Friday, February 11, 2011

How to store rounded number in Oracle ?

If you have a requirement to store the numbers rounded to nearest hundreds , what would be the easy way ?

You can  satisfying this requirement by defining the column as number ( xxx, -2) ...
Here is an example ...

SQL> drop table t;

Table dropped.

SQL> create table t ( col1 number( 5,-2) ) ;
Table created.

SQL> insert into t values ( 34579) ;
1 row created.


SQL> insert into t values ( 987562.25) ;
1 row created.


SQL> select * from t ;


COL1
----------
34600
987600

By declaring at the table level , we can ensure the value entered is always rounded to nearest hundreds , no matter what the application is.

This may not be easily achievable in other DBMS ...


This is yet another reason for the applications to be database dependent . 

For the "pro - database independent"  application developers / architects.. do you have any suggestions ?

No comments:

Post a Comment