我在表中有一個包含 json 資料的 clob 欄位。我想從該 json 資料中獲取一個值并對其進行處理。如何得到它?
示例:表 A 有 2 列:id 和 accounts,其中 id 是字串,account 是帶有 json 資料的 clob。
Json 資料的存盤方式如下:
{
"facebook":"[email protected]",
"gmail":"[email protected]",
"instagram":"[email protected]"
}
現在我想從表中的 clob 中獲取 gmail 的值,它應該如下所示:
識別郵箱
...
在此先感謝您的幫助!
uj5u.com熱心網友回復:
如果您使用的是 Oracle 資料庫 12.1.0.2 或更高版本,則可以使用JSON_VALUE
WITH
table_a (id, accounts)
AS
(SELECT 'A1', EMPTY_CLOB () || '{
"facebook":"[email protected]",
"gmail":"[email protected]",
"instagram":"[email protected]"
}' FROM DUAL
UNION ALL
SELECT 'C2', EMPTY_CLOB () || '{
"facebook":"[email protected]",
"gmail":"[email protected]",
"instagram":"[email protected]"
}' FROM DUAL
UNION ALL
SELECT 'B3', EMPTY_CLOB () || '{
"facebook":"[email protected]"
}' FROM DUAL)
SELECT id, json_value (accounts, '$.gmail') AS gmail
FROM table_a;
ID GMAIL
_____ ______________
A1 qwe@jpg.com
C2 lrt@qrs.com
B3
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422024.html
標籤:
