下面是 xmldata 列中的 XML 数据。
<Inquiry>
<MemberCode>56</MemberCode>
<MemberName>COMP</MemberName>
<Date>16</Date>
</Inquiry>
如何使用 XMLGET 从内部标记中仅提取值
SELECT TOP 100
KEY,
GET(b.VALUE,'@')::STRING as name, --returns Inquiry
b.VALUE:"$"[1]."$"[1],--returns null
GET(XMLGET(b.VALUE, GET(b.VALUE,'@')::STRING), '$') as value1,--returns null
-- XMLGET(VALUE,GET(b.VALUE,'@')::STRING):"$" as value,--returns null
b.value as children,-- returns full xmldata
b.this
FROM
(SELECT
KEY,
VALUE
,this
from
FULL_XML,
LATERAL FLATTEN(XMLGET(XMLGET(XML_DATA,'Report'),'Inquiries'):"$") )b ;
值列的预期输出是:
56COMP16
如果您的对象是单级事物,那么要访问该事物的成员,您只需命名它们,转换为字符串,然后连接它们:
with data_in_cte as (
select parse_xml('<Inquiry>
<MemberCode>56</MemberCode>
<MemberName>COMP</MemberName>
<Date>16</Date>
</Inquiry>') as XML_DATA
)
select
get(xmlget(xml_data,'MemberCode'),'$')::text as a,
get(xmlget(xml_data,'MemberName'),'$')::text as b,
get(xmlget(xml_data,'Date'),'$')::text as c,
a || b || c as result
from data_in_cte