是否可以从xml数据动态生成我的SQL表的列名?

时间:2017-08-28 17:56:31

标签: mysql xml

我的意思是说我希望属性名称作为列名后跟值 数据就像这样(小部分)

<row _id="1" _uuid="0BEBAB70-5985-4A1C-862F-A842BF7F293C" _position="1" _address="http://data.montgomerycountymd.gov/resource/_6rqk-pdub/1">
<full_name>Aarhus, Pam J.</full_name><gender>F</gender><current_annual_salary>68878.16</current_annual_salary><_2015_gross_pay_received>72336.79</_2015_gross_pay_received>
<department>POL</department><department_name>Department of Police</department_name>
<division>MSB Information Management and Technology Division Data Systems Section</division><assignment_category>Fulltime-Regular</assignment_category>
<position_title>Office Services Coordinator</position_title><date_first_hired>1986-09-22T00:00:00</date_first_hired></row>![enter image description here](https://i.stack.imgur.com/zXqHe.jpg)

我需要输出为  第一行,作为一列 全名为一列

1 个答案:

答案 0 :(得分:0)

CREATE PROCEDURE dynamic(IN xml_data varchar)
BEGIN
    /* Put your logic and set your sql dynamic from xml_data */
    SET @sql = ...

    PREPARE statement FROM @sql;
    EXECUTE statement;
    DEALLOCATE PREPARE statement;
END