Understand Mappings with Different Data Types This page last changed on Nov 28, 2008. .stickable, h1, h2, h3, h4, h5 false true Show Sticky notes Hide Sticky notes Save Cancel Oracle Data Service Integrator Documentation > Data Services Developer's Guide # How To Understand Mappings with Different Data Types This topic describes casts between elements of different data types in an update map. Overview Built-In Cast Functions Custom Cast Functions See Also ## Overview In an update map, you may need to map elements of different data types between a return type and an underlying data source. For example, a return type might contain an xsd:dateTime element that maps to an xs:date element in the data source. When data types differ, you need to cast between them in order to enable the update map. Type differences occur because a logical data service design can differ from actual physical data sources or because data types used by an underlying data source are unknown at design time. When the update map is first generated, the element in the data source has no mapping and a warning icon. ##### The Element Initially with No Mapping If you draw a mapping line in Update Map view, from the xsd:dateTime value in the return type to the xsd:date value in the update block, the element becomes disabled. ##### An Error Due to Data Type Mismatch You can fix this type of error by using different techniques to cast, according to the data types you are casting. First, review the built-in datatypes chart in the XML Schema Datatypes specification to understand the hierarchies of data types used in XML Schema. The type xs:string and its subtypes belong to one type hierarchy, and the type xs:decimal and its subtypes belong to another. Casts between elements of different types are handled in one of three ways: Type promotion. If both data types are in the same type hierarchy and the cast moves up the hierarchy, Oracle Data Service Integrator casts them implicitly. This is known as type promotion. For example, xs:token is promoted to xs:string and xs:integer is promoted to xs:decimal. Implicit casts are implemented in Oracle Data Service Integrator according to the XQuery 1.0 specification. Built-in cast function. If the types do not use a cast up the same type hierarchy and type promotion does not occur, you can use a built-in XQuery function available from the Design Palette. Custom cast function. If a built-in XQuery function is not available, you can write your own custom cast function in the Source tab of your primary logical data service or in a specialized library data service that performs casting. ## Built-In Cast Functions If a built-in function provides the cast you need, you can simply drag it from the Design Palette to the expression editor and enter argument values. ##### Built-In XQuery Casting Functions ## Custom Cast Functions Before you write a custom XQuery cast function, make sure that XQuery allows the cast you want to perform. Check the casting section in the XQuery 1.0 specification to understand the rules for casting between types in XQuery, especially the chart that describes casting between primitive types. Remember these general guidelines: The primitive type chart shows which casts can be performed between primitive types. For example, an integer (such as 44) can always be cast to a string ("44"). However, a string can only be cast to an integer in some cases. The string "55" can be cast to the integer 55, but the string "hello" cannot be cast to an integer. If both the source and target types are derived from the same primitive type, you can cast between them. If the source and target types are derived from different primitive types, you are casting across the type hierarchy. In general, you need to cast the source type up the hierarchy to its primitive type; then, cast from the primitive type of the source to the primitive type of the target; and last, cast from the primitive type of the target to the target type (see the rules in the XQuery 1.0 specification). Once you write the cast function, you can test it in Workshop for WebLogic, before you run it with a client application. ## See Also ##### How To Cast Using a Built-In XQuery Function Cast Using a Custom XQuery Function Test an Update Map Cast ##### Other Resources Built-in datatypes chart Primitive types casting chart (scroll down) XML Schema Datatypes Specification XQuery 1.0 Specification

Document generated by Confluence on Jan 13, 2009 15:57