我在下面写了一个查询来生成一个xml文件
SELECT XMLElement("Providers",
XMLElement("Provider" ,XMLAttributes(
"Unique ID" as "UniqueId"),
XMLElement("ProviderType", "Provider Type"),
XMLElement("Specialities",
XMLElement("Speciality", "Specialty")),
XMLElement("Relationships",
XMLElement("Relationship", "Relationship")),
XMLElement("ServiceAddress",
XMLElement("AddressLine1","P Address Line 1"),
XMLElement("AddressLine2","P Address Line 2"),
XMLElement("AddressLine3","P Address Line 3"),
XMLElement("AddressLine4","P Address Line 4"),
XMLElement("City","Service city description"),
XMLElement("Region","PState_Province_Region"),
XMLElement("PostalCode","PPostal Code"),
XMLElement("IsoCountryCode","ServiceCountry ISO code")),
XMLElement("Contacts",
XMLElement("ContactInfo",
XMLElement("ContactType","Contact Type"),
XMLElement("Name","Contact Name"),
XMLElement("Title","Contact Title"),
XMLElement("Function","Contact Function"),
XMLElement("PhoneNo","Contact Phone Number"),
XMLElement("CellNo","Contact Cell Phone Number"),
XMLElement("Email","Contact E-mail") ))))
AS "RESULT"
FROM providers_xml
但是这会为表提供程序中的每一行创建单独的xml文件,如下所示
档案1
<?xml version="1.0"?>
-<Providers>
-<Provider UniqueId="AA">
<ProviderType>1</ProviderType>
-<Specialities>
<Speciality>210</Speciality>
</Specialities>
-<Relationships>
<Relationship/></Relationships>
-<ServiceAddress>
<AddressLine1>ABC</AddressLine1>
<AddressLine2/><AddressLine3/>
<AddressLine4/>
<City>city123</City>
<Region/>
<PostalCode/>
<IsoCountryCode>US</IsoCountryCode>
</ServiceAddress>
-<Contacts>
-<ContactInfo>
<ContactType>1</ContactType>
<Name>General Contact</Name>
<Title/>
<Function/>
<PhoneNo/>
<CellNo/>
<Email/>
</ContactInfo>
</Contacts>
</Provider>
</Providers>
文件2
<?xml version="1.0"?>
-<Providers>
-<Provider UniqueId="ABC">
<ProviderType>1</ProviderType>
-<Specialities>
<Speciality>100</Speciality>
</Specialities>
-<Relationships>
<Relationship/></Relationships>
-<ServiceAddress>
<AddressLine1>zxy</AddressLine1>
<AddressLine2/><AddressLine3/>
<AddressLine4/>
<City>city300</City>
<Region/>
<PostalCode/>
<IsoCountryCode>US</IsoCountryCode>
</ServiceAddress>
-<Contacts>
-<ContactInfo>
<ContactType>2</ContactType>
<Name>General Contact</Name>
<Title/>
<Function/>
<PhoneNo/>
<CellNo/>
<Email/>
</ContactInfo>
</Contacts>
</Provider>
</Providers>
但我需要所有这些文件,如下所示
-<Providers>
-<Provider UniqueId="AA">
<ProviderType>1</ProviderType>
-<Specialities>
<Speciality>210</Speciality>
</Specialities>
-<Relationships>
<Relationship/></Relationships>
-<ServiceAddress>
<AddressLine1>ABC</AddressLine1>
<AddressLine2/><AddressLine3/>
<AddressLine4/>
<City>city123</City>
<Region/>
<PostalCode/>
<IsoCountryCode>US</IsoCountryCode>
</ServiceAddress>
-<Contacts>
-<ContactInfo>
<ContactType>1</ContactType>
<Name>General Contact</Name>
<Title/>
<Function/>
<PhoneNo/>
<CellNo/>
<Email/>
</ContactInfo>
</Contacts>
</Provider>
-<Provider UniqueId="ABC">
<ProviderType>1</ProviderType>
-<Specialities>
<Speciality>100</Speciality>
</Specialities>
-<Relationships>
<Relationship/></Relationships>
-<ServiceAddress>
<AddressLine1>zxy</AddressLine1>
<AddressLine2/><AddressLine3/>
<AddressLine4/>
<City>city300</City>
<Region/>
<PostalCode/>
<IsoCountryCode>US</IsoCountryCode>
</ServiceAddress>
-<Contacts>
-<ContactInfo>
<ContactType>2</ContactType>
<Name>General Contact</Name>
<Title/>
<Function/>
<PhoneNo/>
<CellNo/>
<Email/>
</ContactInfo>
</Contacts>
</Provider>
</Providers>
请帮助获得所需的o / p
答案 0 :(得分:0)
添加XMLAGG子句。
SELECT XMLElement("Providers",
**XMLAGG(**
XMLElement("Provider" ,XMLAttributes(
"Unique ID" as "UniqueId