gpt4 book ai didi

mysql - 将 XML 导入 mySQL 时列名无效?

转载 作者:行者123 更新时间:2023-11-30 01:29:39 25 4
gpt4 key购买 nike

我有一个 XML 文件,正在尝试将其导入到 mySQL 中。但是,由于变量名称中包含“-”,因此使用 LOAD XML 查询不起作用。如何将其导入数据库并处理无效字符?:

    <?xml version="1.0" encoding="UTF-8"?>
<projects type="array">
<project>
<active type="boolean">true</active>
<bill-by>none</bill-by>
<billable type="boolean">true</billable>
<budget type="decimal" nil="true"/>
<budget-by>none</budget-by>
<client-id type="integer">999</client-id>
<code></code>
<cost-budget type="decimal" nil="true"/>
<cost-budget-include-expenses type="boolean">false</cost-budget-include-expenses>
<created-at type="datetime">2013-06-27T18:10:26Z</created-at>
<fees type="decimal" nil="true"/>
<highrise-deal-id type="integer" nil="true"/>
<hourly-rate type="decimal" nil="true"/>
<id type="integer">38125</id>
<name>Banking</name>
<notify-when-over-budget type="boolean">false</notify-when-over-budget>
<over-budget-notification-percentage type="decimal">80.0</over-budget-notification-percentage>
<over-budget-notified-at type="date" nil="true"/>
<show-budget-to-all type="boolean">false</show-budget-to-all>
<updated-at type="datetime">2013-06-27T18:13:10Z</updated-at>
<estimate nil="true"/>
<estimate-by>none</estimate-by>
<notes></notes>
<hint-earliest-record-at type="NilClass">2013-06-24</hint-earliest-record-at>
<hint-latest-record-at type="NilClass">2013-06-30</hint-latest-record-at>
<hint-earliest-record-at>2013-06-24</hint-earliest-record-at>
<hint-latest-record-at>2013-06-30</hint-latest-record-at>
</project>

最佳答案

您必须修复 XML 文件中的字段名称。

此外,您的 XML 文件还存在另一个问题: <hint-earliest-record-at><hint-latest-record-at>出现两次,因此您必须选择一个进行删除或重命名。

我尝试了一个实验:

  1. 创建一个表格,其中的列不包含破折号。
  2. 针对该表创建可更新的 VIEW,并使用破折号字符定义 View 的列名称
  3. 将 XML 加载到 VIEW 中,希望它插入到基表的相应列中。

但这没有用。它插入了一行,但所有值都作为 NULL 插入。

我还测试了创建一个具有正常列名称(不带破折号)的 VIEW,然后编辑了 XML 中的字段名称。通过 VIEW 加载此 XML 有效,并且行被插入到基表中。所以我知道 LOAD XML 可与可更新的 VIEW 一起使用。

关于mysql - 将 XML 导入 mySQL 时列名无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17622530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com