Showing posts with label Database Independence. Show all posts
Showing posts with label Database Independence. Show all posts

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 ?

Wednesday, July 14, 2010

Database Independence...

Write one database code independent of DBMS ....


We will write the SQL to the lowest common denominator ... Should not use Vendor's Extensions ...

Sounds like noble cause ....


Let us translate into real world scenario ...

I have Chevy Impala which has built in OnStar and BMW with built in GPS ... We should not use as this is not common across these vehicles ....

Sounds right ? ....

For an example , Oracle has unique features like Connect By , Analytics , MODEL clause , Bitmap Index , etc.,  and SQL Server has filtered index , ....
These DBMS are catching up to each other on some of the features like PIVOT , Analytics ,...

Besides these , locking and concurrency is implemented in totally different way between these DBMS.

If you assume , this is the way it is supposed to work in Oracle from SQL Server's perspective , you could be in surprise.

Best way to learn a DBMS , is to learn the DBMS from the scratch ( unlearn the stuff from other DBMS ) .

Best way to use the DBMS is to explore the features of that DBMS ( be it Oracle , DB2 , Sybase / SQL Server , MySQL .. )  and use it to the fullest extent possible.

Best way to achieve database indepdence , is to have transactional APIS built into the application that will call the database with packaged procedures / functions ( in oracle ) or Procedures and Functions ( in Non Oracle ) .... ie , there will no embedded SQL ....  By this method  , we can utlize the DB-centric calls properly ...

We can have the cake and eat it too :- )