Search This Blog

Thursday, August 18, 2011

Issues with Implicit conversion

Implicit conversion does only if the operands data type differs

‘01’  ( varchar )  < 6  (int)

Then implict casting will be done as   1 <  6


If operands are of same data type no conversion is needed.

‘01’ = ‘1’


Strings are compared character by character ( ASCII value ).   

Comparisions must always be done in numeric format

Example:

  1. comparison done in string format

                 ‘01/08/2011’  >  ‘01/02/2012’   

           This evaluate to true.

  1. Comparison done in the correct data type format

To_date( ‘01/08/2011’,’mm/dd/yyyy’)  > To_date ( ‘01/02/2012’,’mm/dd/yyyy’)


Thumb rule : Don’t trust on Implicit conversions.

No comments:

Post a Comment