Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用MySQL提取值_Mysql_Sql_Xml_Extract Value - Fatal编程技术网

使用MySQL提取值

使用MySQL提取值,mysql,sql,xml,extract-value,Mysql,Sql,Xml,Extract Value,我试图从加载到数据库列(文件输出)的XML输出中提取用户名值。我的查询返回了一个空值,并且没有像我期望的那样执行。谢谢你的帮助 XML输出: <soap:Envelope xmlns:ones="http://onesource.gmtorque.com" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-2004

我试图从加载到数据库列(文件输出)的XML输出中提取用户名值。我的查询返回了一个空值,并且没有像我期望的那样执行。谢谢你的帮助

XML输出:

    <soap:Envelope xmlns:ones="http://onesource.gmtorque.com" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <soap:Header>
        <wsse:Security>
          <wsse:UsernameToken>
            <wsse:Username>username_prod</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
          </wsse:UsernameToken>
        </wsse:Security>
      </soap:Header>
</soap:Envelope>

预期值为username\u prod

您的XML示例格式不正确,因为它缺少结束标记


您遇到的问题是MySQL的一个bug。您试图解析的XML很可能太长。我很确定这和这个bug有关:。为了避免这个错误,您可以只提取您试图导航的XML部分,或者只使用另一种方法提取您正在寻找的值。无论如何,我选择的解决方案是提取您试图通过XPath导航的XML,并使用您提供的XPath查询来提取结果

SELECT DISTINCT RR.consumer_ID
    , RR.file_output
    , RR.response_message
    , RR.external_ID
    , RR.create_DTM
    , E.client_license_ID
    , ExtractValue(CONCAT(LEFT(RR.file_output, (INSTR(LEFT(RR.file_output,1000), "</soap:Header>") + 14)),"</soap:Envelope>"), '//wsse:Security/wsse:UsernameToken/wsse:Username') AS Username
FROM kettle_data_transfer.Records RR
    JOIN kettle_data_transfer.Event_Mappings EM ON RR.event_mapping_ID = EM.event_mapping_ID AND RR.data_transfer_ID = EM.data_transfer_ID
    JOIN efn.Events E on EM.event_ID = E.event_ID
WHERE 0=0
    AND RR.data_transfer_ID = 43
    AND RR.failure_code = 0
    AND RR.mode = 'production'
    AND RR.`ignore` = 0
    AND RR.create_DTM > '2015-10-25';
选择不同的RR.consumer\u ID
,RR.file\u输出
,RR.response\u消息
,RR.external\u ID
,RR.create\u DTM
,E.客户端许可证ID
,ExtractValue(CONCAT(左(RR.file_输出,(INSTR(左(RR.file_输出,1000),“”+14)),“”),“//wsse:Security/wsse:UsernameToken/wsse:Username”)作为用户名
从釜\u数据\u传输记录RR
在RR.Event\u mapping\u ID=EM.Event\u mapping\u ID和RR.data\u transfer\u ID=EM.data\u transfer\u ID上加入kettle\u data\u transfer.Event\u mapping EM
在EM.event\u ID=E.event\u ID上加入efn.Events E
其中0=0
和RR.data\u transfer\u ID=43
和RR.failure_code=0
和RR.mode='production'
和RR.`ignore`=0
和RR.create_DTM>“2015-10-25”;

无论如何,这应该能解决你的问题。

就连我也遇到了同样的问题

但是,如果您不相信使用“提取所需xml的部分”,您可以切换到MYSQL服务器版本5.6或更高版本。该问题/缺陷已在5.6及更高版本中修复


这应该可以解决您的问题。

我没有包括整个XML文件,因为它存在于表中。所有标记都已关闭。fiddle示例是否在您的数据库中成功运行?如果您使用与您的问题完全相同的XML,它是否有效?
SELECT DISTINCT RR.consumer_ID
    , RR.file_output
    , RR.response_message
    , RR.external_ID
    , RR.create_DTM
    , E.client_license_ID
    , ExtractValue(CONCAT(LEFT(RR.file_output, (INSTR(LEFT(RR.file_output,1000), "</soap:Header>") + 14)),"</soap:Envelope>"), '//wsse:Security/wsse:UsernameToken/wsse:Username') AS Username
FROM kettle_data_transfer.Records RR
    JOIN kettle_data_transfer.Event_Mappings EM ON RR.event_mapping_ID = EM.event_mapping_ID AND RR.data_transfer_ID = EM.data_transfer_ID
    JOIN efn.Events E on EM.event_ID = E.event_ID
WHERE 0=0
    AND RR.data_transfer_ID = 43
    AND RR.failure_code = 0
    AND RR.mode = 'production'
    AND RR.`ignore` = 0
    AND RR.create_DTM > '2015-10-25';