我們在雪花資料庫中接收 XML 檔案。有一個標簽可以出現多次或不出現。我們希望將此標記提取為 XML(或更好地轉換為 JSON)作為 Variant,同時將其余標記傳遞為表格格式。
問題:我不知道如何選擇一種型別的所有標簽,而不僅僅是一個。
XML 示例:
<container>
<contentOne>Here is a 1</contentOne>
<contentTwo>Here is a 2</contentOne>
<contentDetail>D1</contentDetail>
<contentDetail>D2</contentDetail>
<contentDetail>D3</contentDetail>
</container>
我想在我的表中的以下行:
內容一 | 內容二 | 內容詳情 |
---|---|---|
這是一個 1 | 這是一個 2 | <contentDetail>D1</contentDetail><contentDetail>D2</contentDetail><contentDetail>D3</contentDetail> |
你會如何處理這個問題?
uj5u.com熱心網友回復:
你可以試試這個嗎?
WITH xmldata AS
(
SELECT 1 record_no,
Parse_xml( '<container>
<contentOne>Here is a 1</contentOne>
<contentTwo>Here is a 2</contentTwo>
<contentDetail>D1</contentDetail>
<contentDetail>D2</contentDetail>
<contentDetail>D3</contentDetail>
</container>') xml
)
SELECT xmlget( xml,'contentOne'):"$"::string contentone,
xmlget( xml,'contentTwo'):"$"::string contenttwo,
listagg( details.value::string, '' ) contentdetails
FROM xmldata,
lateral flatten(XML:"$" ) details
WHERE get( details.value, '@' ) = 'contentDetail'
GROUP BY record_no,
1,
2;
------------- ------------- -----------------------------------------------------------------------------------------------------
| CONTENTONE | CONTENTTWO | CONTENTDETAILS |
------------- ------------- -----------------------------------------------------------------------------------------------------
| Here is a 1 | Here is a 2 | <contentDetail>D1</contentDetail><contentDetail>D2</contentDetail><contentDetail>D3</contentDetail> |
------------- ------------- -----------------------------------------------------------------------------------------------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/474974.html
上一篇:底部導航頂部的FAB