You must use the convert function to convert an instance of a class to an instance of a subclass of the class. For example:
update emps set mailing_addr = convert(Address2Line, home_addr) where mailing_addr is null
The narrowing conversions in the update statement cause an exception if they are applied to any home_addr column that contains an Address instance that is not an Address2Line. You can avoid such exceptions by including a condition in the where clause:
update emps set mailing_addr = convert(Address2Line, home_addr) where mailing_addr is null and home_addr>>getClass( )>>toString( ) = 'Address2Line'
The expression “home_addr>>getClass( )>>toString( )” invokes getClass( ) and toString( ) methods of the Java Object class. The Object class is implicitly a superclass of all classes, so the methods defined for it are available for all classes.
You can also use a case expression:
update emps set mailing_addr = case when home_addr>>getClass( )>>toString( ) ='Address2Line' then convert(Address2Line, home_addr) else null end where mailing_addr is null