ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

SQL Server使用OPENXML反序列化XML

2022-06-24 17:05:15  阅读:43  来源: 互联网

标签:XML varchar List value Item SQL 序列化 data row


DECLARE @data AS xml = N'<row ACOCLI="00330" ARAGS1="Some description" ACOFIS="01266820248" AEMAIL=" " ACOAGE=" " AANNUL=" " ANOMIG="Some Name"/>';
 SELECT @data.value('(row/@ACOCLI)[1]','varchar(6)'), @data.value('(row/@ARAGS1)[1]','varchar(30)'), @data.value('(row/@ACOFIS)[1]','varchar(15)'), 
@data.value('(row/@AEMAIL)[1]','varchar(6)'), @data.value('(row/@ACOAGE)[1]','varchar(6)'), 
@data.value('(row/@AANNUL)[1]','varchar(6)'), @data.value('(row/@ANOMIG)[1]','varchar(15)');

SQL 示例。【此方法支持单条xml 反序列化】

DECLARE @data AS xml = '<List Name="Default" Fields=""><Item Id="" UserId="" EmployeeName="许庆贵" WorkNo="3007" ChangeTypeAdd="成手调入" 
ChangeTypeDel="" InDeptId="PRO0001I.PROP10DD.PROP10DM" InDept="土建室" OutDeptId="" OutDept="" ChangeDate="2007-12-12" Remark="" />
<Item Id="" UserId="" EmployeeName="李晶" WorkNo="3008" ChangeTypeAdd="成手调入" ChangeTypeDel=""
InDeptId="PRO0001I.PROP10DD.PROP10DY" InDept="暖通室" OutDeptId="" OutDept="" ChangeDate="2007-12-12" Remark="" /></List>'; SELECT @data.value('(List/Item/@EmployeeName)[1]','varchar(6)'), @data.value('(List/Item/@WorkNo)[1]','varchar(30)'), @data.value('(List/Item/@ChangeTypeAdd)[1]','varchar(15)'), @data.value('(List/Item/@ChangeTypeDel)[1]','varchar(6)'), @data.value('(List/Item/@InDeptId)[1]','varchar(6)'), @data.value('(List/Item/@InDept)[1]','varchar(6)'), @data.value('(List/Item/@ChangeDate)[1]','varchar(15)');

 

标签:XML,varchar,List,value,Item,SQL,序列化,data,row
来源: https://www.cnblogs.com/wintuzi/p/16409502.html

专注分享技术,共同学习,共同进步。侵权联系[[email protected]]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有