Home > database >  Mysql converts XML or json data to form
Mysql converts XML or json data to form

Time:09-25

I will need an XML string data or the json data into a mysql in tabular form,
Json_extract function can handle only a single json data, unable to process json arrays, ExtractValue function out of data are spliced together, don't know how to separate, there is no other way, consult everybody a great god


Data sample:
 [{" fCategoryId ":" 796 ", "fCondition" : "0.8"}, {" fCategoryId ":" 730 ", "fCondition" : "0.05"}, {" fCategoryId ":" 731 ", "fCondition" : "0.05"}] 


 select the CONVERT (json_extract (' {" fCategoryId ":" 796 ", "fCondition" : "0.8"} ', '$. FCondition'), a DECIMAL (5, 2)) AS fcid; 


If input a json array, no output

 & lt; Jrt> 

1006 & lt;/fCategoryId>
0.40 & lt;/fCondition>


1007 & lt;/fCategoryId>
0.30 & lt;/fCondition>


1008 & lt;/fCategoryId>
0.30 & lt;/fCondition>



 SET @ xmlstring='& lt; Jrt>   1006 & lt;/fCategoryId>  0.40 & lt;/fCondition>    1007 & lt;/fCategoryId>  0.30 & lt;/fCondition>    1008 & lt;/fCategoryId>  0.30 & lt;/fCondition>   '
;

The SELECT ExtractValue (@ xmlstring, '/JRT/item/fCategoryId) as fCategoryId, ExtractValue (@ xmlstring,'/JRT/item/fCondition) as fCondition;


The data form is
FCategoryId | fCondition
1006 1007 1008 | 0.40 0.30 0.30
  • Related