您可以使用获取 itemid 和描述的值JSON_VALUE
。请参阅下面的示例
WITH
json_podcast_data (json_str)
AS
(SELECT '[
{
"itemid" : "18726539",
"duration" : "19:28",
"title" : "Flight Plan for Trading: Market Lessons from My Pilot Dad",
"description" : "<p>Learning to fly an airplane can build an excellent structured thought process for navigating markets</p>",
"pubDate" : "Wed, 14 Apr 2021 18:04:19 +0000"
}
]'
FROM DUAL)
SELECT json_value (json_str, '$[0].itemid') AS itemid,
json_value (json_str, '$[0].description') AS description
FROM json_podcast_data;
ITEMID DESCRIPTION
___________ ______________________________________________________________________________________________________________
18726539 <p>Learning to fly an airplane can build an excellent structured thought process for navigating markets</p>
如果您的 JSON 数组中有多个项目,您可以使用该JSON_TABLE
函数列出数组中的所有项目。
/* Formatted on 27-Jul-2021 5:51:38 PM (QP5 v5.354) */
WITH
json_podcast_data (json_str)
AS
(SELECT '[
{
"itemid" : "18726539",
"duration" : "19:28",
"title" : "Flight Plan for Trading: Market Lessons from My Pilot Dad",
"description" : "<p>Learning to fly an airplane can build an excellent structured thought process for navigating markets</p>",
"pubDate" : "Wed, 14 Apr 2021 18:04:19 +0000"
},
{
"itemid" : "23456",
"duration" : "10:15",
"title" : "Test Title",
"description" : "<p>Some cool podcast</p>",
"pubDate" : "Wed, 14 Apr 2021 18:04:19 +0000"
}
]'
FROM DUAL)
SELECT j.itemid, j.description
FROM json_podcast_data
CROSS JOIN
JSON_TABLE (
json_str,
'$[*]'
COLUMNS itemid NUMBER PATH '$.itemid', description VARCHAR2 PATH '$.description') j;
ITEMID DESCRIPTION
___________ ______________________________________________________________________________________________________________
18726539 <p>Learning to fly an airplane can build an excellent structured thought process for navigating markets</p>
23456 <p>Some cool podcast</p>