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.

Tuesday, August 2, 2011

Alter session Set Current_Schema=UserXYZ

Using this we can refer to the objects in "SchemaUserX" without any Synonyms or schema reference.

All the objects will be referenced as SchemaUserX.Objectname

Example : select * from tablename

will be transformed to

               Select * from SchemaUserX.tablename;


Statement to execute:


ALTER SESSION SET CURRENT_SCHEMA = SchemaUserX


This will be equivalent to Logging into SchemaUserX and then executing the sql / pl/sql blocks.