首页 \ 问答 \ 查询XML类型数据列并插入到SQL Server表中(Query XML type data column and insert into SQL Server table)

查询XML类型数据列并插入到SQL Server表中(Query XML type data column and insert into SQL Server table)

希望有人可以帮我解决SQL Server问题,在我们的一个表中,我有一个longtext数据类型,其中包含XML类型格式的数据,如下所示:

<entry name=\"cleaned_sectors\" type=\"uint\">585937500</entry>\r\n<entry name=\"bad_sectors\" type=\"uint\">0</entry>\r\n<entry name=\"state\"

通常,当我在表格中遇到XML时,它看起来像这样:

<header>data</Header><Manufacturer>Dell</Manufacturer>

我生成一个查询来获取数据,如下所示:

SELECT 
    Tbl.Col.value('Header[1], 'nvarchar(50)'), Tbl.Col.value('manufacturer[1].'nvarchar(50)') 
FROM ...

但是你会注意到这个数据不是标准的XML,并且每个标签都使用\“来包含,有没有一种方法可以查询包含的数据,然后将其导入到另一个表中?

预期的输出将如下所示:

Cleaned Sectors | Bad Sectors
585937500       | 0

任何查询数据的帮助都会很棒,因为我一直在尝试几个小时。 谢谢。


Hoping someone can help me with a SQL Server issue, In one of our tables I have a longtext data type which contains data in an XML type format as below:

<entry name=\"cleaned_sectors\" type=\"uint\">585937500</entry>\r\n<entry name=\"bad_sectors\" type=\"uint\">0</entry>\r\n<entry name=\"state\"

Generally when I have come across XML in a table it looks like this:

<header>data</Header><Manufacturer>Dell</Manufacturer>

And I generate a query to obtain the data like so:

SELECT 
    Tbl.Col.value('Header[1], 'nvarchar(50)'), Tbl.Col.value('manufacturer[1].'nvarchar(50)') 
FROM ...

However you will notice this data isn't standard XML and each tag is contained using \" is there a way I can query the data contained with the aim to then import this into another table?

Expected output would be something like:

Cleaned Sectors | Bad Sectors
585937500       | 0

Any help with querying the data would be brilliant as I have been trying for hours. Thank you.


原文:https://stackoverflow.com/questions/32467187
更新时间:2023-07-18 18:07

最满意答案

按照指示说的去做:

import qualified Text.Parsec

parse :: String -> Stm
parse str =
  case Text.Parsec.parse procParser "" str of
    Left e  -> error $ show e
    Right r -> r

Do exactly what the instructions say:

import qualified Text.Parsec

parse :: String -> Stm
parse str =
  case Text.Parsec.parse procParser "" str of
    Left e  -> error $ show e
    Right r -> r

相关问答

更多
  • 是的, between可能不适合你要找的东西。 当然,对于您的使用案例,我会遵循hammar的建议并抓取现成的SQL解析器。 (个人观点:或者,尽量不要使用SQL,除非你真的需要;使用字符串进行数据库查询的想法是一种历史错误)。 注意:我添加一个名为<++>的运算符,它将连接两个解析器的结果,不管它们是字符串还是字符。 (代码在底部。) 首先,解析括号的任务:顶层将解析相关字符之间的一些东西,这正是代码所说的, parseParen = char '(' <++> inner <++> char ')' ...
  • 在这种情况下fail等同于parserFail定义的Text.Parsec.Prim : parserFail :: String -> ParsecT s u m a parserFail msg = ParsecT $ \s _ _ _ eerr -> eerr $ newErrorMessage (Message msg) (statePos s) 由于newErrorMessage和newErrorMessage都创建了ParseError ,因此parserFail这种变体也 ...
  • 您可以使用quickcheck测试IO操作: http : //hackage.haskell.org/packages/archive/QuickCheck/2.4.1.1/doc/html/Test-QuickCheck-Monadic.html You can test IO actions with quickcheck: http://hackage.haskell.org/packages/archive/QuickCheck/2.4.1.1/doc/html/Test-QuickCheck-M ...
  • ParsecT和Parsec 在parsec 3中, ParsecT和Parsec是在Text.Parsec.Prim模块中定义和解释的: data ParsecT suma ParsecT suma是一个流类型为s ,用户状态类型为u ,基础monad m和返回类型为a的解析器。 (流类型的例子是String , ByteString和Text 。) Parsec只是专门用于Identity monad的ParsecT一个版本: type Parsec su = ParsecT su Identity m ...
  • 我猜这个optionMaybe dimensParser是optionMaybe dimensParser ,当输入"hello,..." ,尝试使用dimensParser 。 这失败了,所以optionMaybe返回Nothing成功,并且不消耗任何输入部分。 最后一部分是至关重要的部分:在返回Nothing之后,要解析的输入字符串仍然是"hello,..." 。 此时sepBy尝试解析char ',' ,它失败了。 因此,它推断列表已结束,并终止输出列表,而不再消耗任何输入。 如果要跳过其他实体,则需 ...
  • 更新2: 似乎这个功能完成了工作,但不确定它是多么惯用。 没关系,但是它并不像你想要的那样有效: > words "Hello world" ["Hello","world"] > parse wordsReplica "" "Hello world" Right ["Hello","","","","","","world"] 不是你想要的。 毕竟,一个单词应该至少包含一个字符。 但是如果你将many更改为many1 ,你会发现另一个错误: > parse wordsReplica ...
  • 在Parsec中, SourceName是一个用于生成错误消息的String 。 在REPL中,这不是很重要: λ> parse expression "" ")" Left "" (line 1, column 1): unexpected ")" expecting expression 如果我们使用"foo"而不是"" ,如果它看起来像这样: Left "foo" (line 1, column 1): unexpected ")" expecting ex ...
  • 虽然jozefg的解决方案与我所提出的解决方案几乎完全相同(并且我完全同意他的所有建议),但有一些小的差异使我认为我应该发表第二个答案: 由于初始例子的预期结果,没有必要将空间分离的部分视为单独的子树。 进一步看到实际计算预期结果的部分(即字符串列表)可能会很有趣。 所以这是我的版本。 正如jozefg所建议的那样,将任务分成几个子任务。 那些是: 将字符串解析为表示某种树的代数数据类型。 收集这棵树的(需要的)子树。 把树变成字符串。 关于1,我们首先需要一个树型数据类型 import Text.Pars ...
  • 按照指示说的去做: import qualified Text.Parsec parse :: String -> Stm parse str = case Text.Parsec.parse procParser "" str of Left e -> error $ show e Right r -> r Do exactly what the instructions say: import qualified Text.Parsec parse :: String -> ...
  • try不会默默地吃错误,但当错误发生时它不会消耗任何令牌(它重置令牌流,AKA回溯)。 错误仍然会发生,但您可以继续进行,就好像分析器根本不消耗任何令牌(通过使用<|> )。 try does not silently eat errors, but it will not consume any tokens when an error occurs (it resets the token stream, AKA backtracks). The error will still occur, but ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)