i am trying to extract values from xml. i am getting problem when xml has attribute. like following Stored Procedure
DELIMITER $$
DROP PROCEDURE IF EXISTS `excel`.`insert_items` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_items`()
BEGIN
SET @xml = '<items><item>
<value columntype="0">Single Line Text_01</value>
<value columntype="1">Single Line Text_12341</value>
<value columntype="2">Single Line Text_21</value>
<value columntype="3">Single Line Text_31</value>
<value columntype="4">Single Line Text_41</value>
</item>
</items>';
SELECT @columntype, ExtractValue(@xml, 'items/item/value[items/item/value/@columntype=0]');
END $$
DELIMITER ;
extractValue() [Oracle SQL] extractValue() is similar to extract(), but it extracts the value without the XML element tags. It only works if it operates on a single element, otherwise, it throws an ORA-19025: EXTRACTVALUE returns value of only one node.
It is possible to obtain XML-formatted output from MySQL in the mysql and mysqldump clients by invoking them with the --xml option.
php $con = mysql_connect("localhost","user","username"); if (! $con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_name", $con); if(! $xml=simplexml_load_file('syntest.
MySQL :: MySQL 8.0 Reference Manual :: 13.2. 8 LOAD XML Statement.
To get a value of an element with attribute columntype="0"
SELECT ExtractValue(@xml, 'items/item/value[@columntype=0]') value;
Output:
| VALUE |
-----------------------
| Single Line Text_01 |
SQLFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With