MySQL Forums
Forum List  »  Newbie

Re: Using ExtractValue( ) function to insert XML data in a table in MySQL
Posted by: Rick James
Date: June 03, 2014 10:39PM

Based on the following, I suggest it won't work as expected:

SET @xml :=
"<ManageAsset>
<Asset>
<SiteGroup>Chicago</SiteGroup>
<SiteNumber>4524</SiteNumber>
<AssetCategory>Passenger Cars</AssetCategory>
<Address>Address 1</Address>
<AssetNumber>Tango</AssetNumber>
</Asset>
<Asset>
<SiteGroup>Cincinnati</SiteGroup>
<SiteNumber>5360</SiteNumber>
<AssetCategory>Passenger Cars</AssetCategory>
<Address>Address 2</Address>
<AssetNumber>Mango</AssetNumber>
</Asset>
</ManageAsset>";

select ExtractValue(@xml,'//ManageAsset/Asset/SiteGroup') as SiteGroup,
ExtractValue(@xml,'//ManageAsset/Asset/SiteNumber') as SiteNumber,
ExtractValue(@xml,'//ManageAsset/Asset/AssetCategory') as AssetCategory,
ExtractValue(@xml,'//ManageAsset/Asset/Address') as Address,
ExtractValue(@xml,'//ManageAsset/Asset/AssetNumber') as AssetNumber;

+--------------------+------------+-------------------------------+---------------------+-------------+
| SiteGroup          | SiteNumber | AssetCategory                 | Address             | AssetNumber |
+--------------------+------------+-------------------------------+---------------------+-------------+
| Chicago Cincinnati | 4524 5360  | Passenger Cars Passenger Cars | Address 1 Address 2 | Tango Mango |
+--------------------+------------+-------------------------------+---------------------+-------------+

Suggest you use this technique for testing other formulations.

Options: ReplyQuote


Subject
Written By
Posted
Re: Using ExtractValue( ) function to insert XML data in a table in MySQL
June 03, 2014 10:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.