I have a feeling I'm missing something very basic here! I'm trying to create an XML document all in one statement. I have some elements which should only appear once each, like shipFrom and shipTo. I have others like lineItems that should repeat.
The way my code is right now I have one shipTo for every lineItem.
It would be cool if I can do this all in one statement, but if I have to fall back to creating each section individually and concatenating them all together in the end, I can resort to that.
Creates the following:
The way my code is right now I have one shipTo for every lineItem.
It would be cool if I can do this all in one statement, but if I have to fall back to creating each section individually and concatenating them all together in the end, I can resort to that.
Code:
WITH lineItems as ( SELECT XMLELEMENT(NAME "LineItem", xmlattributes(row_number() over (order by olprdc) as "lineItemNumber"), XMLFOREST( trim(olprdc) as "Product", oloqty as "Quantity", olsalp as "ExtendedPrice" ) ) as lineItem FROM srbbspiql1 where olcorn = '3102102' ), destination as ( select xmlrow( trim(oaadr1) as "StreetAddress1", trim(oaadr4) as "City", trim(oaspcd) as "MainDivision", trim(substr(oapocd, 3)) as "PostalCode" option row "Destination" ) as shipto from srobsaiq where oacorn = '3102102' and oaadty = 'X' ) SELECT XMLSERIALIZE( XMLELEMENT(NAME "QuotationRequest", xmlattributes(current_date as "documentDate", 'SALE' as "transactionType"), XMLAGG(destination.shipto), XMLAGG(lineItems.lineItem) ) as clob excluding xmldeclaration ) as request --INTO :File_Out FROM lineItems, destination
Creates the following:
Code:
<QuotationRequest documentDate="2020-03-17" transactionType="SALE"> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <Destination> <StreetAddress1>316 NORTH GREEEN RIVER ROAD</StreetAddress1> <City>EVANSVILLE, IN</City> <MainDivision>IN</MainDivision> <PostalCode>47715</PostalCode> </Destination> <LineItem lineItemNumber="1"> <Product>ANDM 026743N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>6530.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="2"> <Product>ANDM 027955N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>18480.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="3"> <Product>BAYM 026379N</Product> <Quantity>2.000</Quantity> <ExtendedPrice>5000.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="4"> <Product>BETM 026009N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>11530.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="5"> <Product>BNEM 024668N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>5060.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="6"> <Product>CTCM 026375N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>2610.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="7"> <Product>GL FREIGHT-IN EQUIPMENT</Product> <Quantity>1.000</Quantity> <ExtendedPrice>6486.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="8"> <Product>GL INSTALLATION EQUIPMENT</Product> <Quantity>1.000</Quantity> <ExtendedPrice>7500.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="9"> <Product>ICEM 026588N</Product> <Quantity>2.000</Quantity> <ExtendedPrice>5650.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="10"> <Product>LAIM 026918N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>46740.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="11"> <Product>NAMM 024570U</Product> <Quantity>1.000</Quantity> <ExtendedPrice>1500.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="12"> <Product>SMTM 026437N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>1790.0000</ExtendedPrice> </LineItem> <LineItem lineItemNumber="13"> <Product>SMTM 027926N</Product> <Quantity>1.000</Quantity> <ExtendedPrice>4350.0000</ExtendedPrice> </LineItem> </QuotationRequest>
Comment