Cast Using a Custom XQuery Function This page last changed on Feb 26, 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 Cast Using a Custom XQuery Function This topic describes how to write a custom XQuery function to cast between elements of different data types in an update map. Example See Also ## Example An example of a custom XQuery cast function is one that casts from integer to string. Suppose the logical data service's return type uses xsd:integer for the TELEPHONE_NUMBER element, while the underlying data source uses xsd:string. ##### Mapping from Integer to String The mapping between the two TELEPHONE_NUMBER elements is initially disabled. The value from the return type is something like 4155551212, which can easily be converted between xsd:integer and xsd:string. Check the type casting chart in the XQuery 1.0 specification to make sure the cast you want to perform is allowed.
| When you test the cast function, you also need to perform the opposite cast (in this case, xsd:string to xsd:integer).
2. To write a custom XQuery cast function: Click the Source tab. Write an XQuery function that takes an argument of the data type you are casting from and returns a value of the data type you are casting to, for example:
       declare function tns:intToString($theint as xs:integer) as xs:string {
                     xs:string($theint)
       };
3. Assign your function to an XML namespace your logical data service uses. Be sure both the parameter and return type are valid XML Schema data types. Then, write a statement that performs the cast. In the Update Map tab, click the element in the data source on the left. At this point, the element is disabled: . Its value is taken from the return type, so its XQuery expression looks something like this:
       fn-bea:value($CUSTOMER/TELEPHONE_NUMBER)
4. Remember that the value from the return type is an xs:integer. Add your new cast function, using the existing expression as its argument, for example:
       tns:intToString(fn-bea:value($CUSTOMER/TELEPHONE_NUMBER))
At this point, the update map should be completely enabled. If the disabled icon on the element does not disappear immediately, click another element in the update map. Test the update map cast to make sure it works as you expect. ## See Also ##### Concepts Understand Mappings with Different Data Types ##### How To Cast Using a Built-In XQuery Function Test an Update Map Cast ##### Other Resources XQuery 1.0 Specification Primitive type casting chart (scroll down)

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