我正在尝试使用JSON更新表,如下所示:
[
{
"NEWDATAPATH": "/user/data/2019/10/28/data-1.zip",
"CATID": -1
},
{
"NEWDATAPATH": "/user/data/2019/10/28/data-2.zip",
"CATID": -2
},
{
"NEWDATAPATH": "/user/data/2019/10/28/data-3.zip",
"CATID": -3
}
]
使用以下查询:
UPDATE IMGTABLE v
SET (DELDATE, DATAPATH) = (SELECT v.EXTENDDATE, j.NEWDATAPATH
FROM json_table(Details, '$[*]' COLUMNS(CATID NUMBER PATH '$.CATID',
NEWDATAPATH VARCHAR(100) PATH '$.NEWDATAPATH')) j
WHERE v.CATID = j.CATID)
WHERE EXISTS (SELECT 1
FROM json_table(Details, '$[*]' COLUMNS(CATID NUMBER PATH '$.CATID')) j
WHERE v.CATID = j.CATID);
上面的代码存在的问题是,它只会更新第一行(CATID = -1),而其余匹配行的感兴趣的列值将为NULL。
---------------------------------------------------------------------
CATID | DELDATE | EXTENDATE| DATAPATH
---------------------------------------------------------------------
-1 | 10-28-2019| 10-28-2020| "/user/data/2019/10/28/data-1.zip"
---------------------------------------------------------------------
-2 | (null) | 10-28-2020| (null)
---------------------------------------------------------------------
-3 | (null) | 10-28-2020| (null)
---------------------------------------------------------------------
任何帮助将不胜感激!