1. Create Conditional Elements in Return Types 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 Create Conditional Elements in Return Types This topic describes how to add a condition to a return type and determine the elements that are returned when the condition is true or false. Add the Condition Create the Expression See Also ## Add the Condition A condition in a return type defines two groups of elements: those returned when an expression is true, and those returned when an expression is false. When you add a condition to a return type, you see two groups of return type elements. To add a condition to the return type: Click the Query Map tab. Right-click an element in the return type, and choose Make Conditional. The conditional element is now duplicated. ## Create the Expression You must add the conditional expression, that determines which element is returned, in the XQuery source. You cannot add a conditional expression in the expression editor. Click the Source tab. The primary Read function now has an if..else clause:
       declare function tns:read() as element(cus:CustomerOrder)*{
       for $CUSTOMER in cus1:CUSTOMER()
       return
           if (true()) then
              <cus:CustomerOrder>
       	 ...
              </cus:CustomerOrder>
           else
              <cus:CustomerOrder>
                ...
              </cus:CustomerOrder>
       };
2. The expression after the if statement is evaluated, and the service returns either the first or second set of elements. The XQuery true() function simply returns the Boolean value true. In the XQuery source, replace true() with another XQuery expression, for example:
       if ( fn:data( $CUSTOMER/LAST_NAME ) = "Black" ) then
You can use any XQuery expression that returns a value of true or false. In this example, if a customer has the last name Black, the first element group is returned. If not, the second element group is returned. To add the value of an element in a For block, use the XQuery fn:data function, which takes the value of an element: <LAST_NAME>Black</LAST_NAME> Click the Query Map tab. In the return type, add or delete elements in either group to create the return groups you want. Remember that the first group is returned if the expression is true, and the second group if the expression is false. Click the Test tab. Choose the Read function, and click Run. Check that the results are what you intend. In this example, the full group of elements is only returned for customers with the last name Black. For other customers, only the CUSTOMER_ID is returned. ## See Also ##### How Tos Create a Return Type Add a Complex Child Element to a Return Type Test a Read Function and Simple Update ##### Other Resources Introduction to XQuery XQuery Tutorial XQuery 1.0 Specification

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