【问题标题】:How to extract an XML Attribute from an XML varchar string using TSQL in SQL Server 2008如何在 SQL Server 2008 中使用 TSQL 从 XML varchar 字符串中提取 XML 属性
【发布时间】:2015-01-15 04:34:29
【问题描述】:

我有一个带有如下 XML 字符串的 varchar 列。我需要在<void property="request">的“字符串”元素中提取数据

在这个例子中,这里是我需要提取的值:

This is the data I need to extract right here.  Testing 123, Testing 1234

任何帮助将不胜感激。

<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.6.0_20" class="java.beans.XMLDecoder"> 
 <object class="java.util.HashMap"> 
  <void method="put"> 
   <string>data</string> 
   <object class="com.globo.abc.process.eb.data.ManualProcessData"> 
    <void property="caseId"> 
     <long>8406</long> 
    </void> 
    <void property="clientId"> 
     <long>25020</long> 
    </void> 
    <void property="context"> 
     <object class="java.util.HashMap"> 
      <void method="put"> 
       <string>TARGET_GROUP</string> 
       <long>102131</long> 
      </void> 
      <void method="put"> 
       <string>TYPE</string> 
       <string>TICKLER</string> 
      </void> 
     </object> 
    </void> 
    <void property="groupStepDefinitionId"> 
     <long>10274</long> 
    </void> 
    <void property="owner"> 
     <string>2256</string> 
    </void> 
    <void property="request"> 
     <string>This is the data I need to extract right here.  Testing 123, Testing 1234</string> 
    </void> 
    <void property="stepDefinitionName"> 
     <string>Manual Task</string> 
    </void> 
   </object> 
  </void> 
 </object> 
 </java>

【问题讨论】:

  • 带镊子 Mono Hijo

标签: xml sql-server-2008


【解决方案1】:

SQL Server 或任何数据库脚本语言都有一个奇怪的“收集”数据概念,它们被称为表。为了遍历数据集合,您需要使用游标并选择字符串。等等等等等等。

如果您尝试提取单个已知标记,则使用 charindex、substr 等。

如果您有多个标记,则必须执行光标和字符索引等。

或者将数据类型更改为 xml

Parse XML in SQL Server

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多