复杂的 Json 文件和 Oracle JSON_TABLE 会导致多行

问题描述 投票:0回答:1

我有一个复杂的 Json 文件(在 CLOB 中)。我会尽力让它变得必不可少:

{
 "c1": "c1",
 "c2": "c2",
 "c3": {
         "a": "a"
       },
 "c4": {
         "c5": {
                "c6": "c6"
               }
       }
}

所以我有这样的疑问:

select tabj.*
 from table_with_clob_column t
    , JSON_TABLE (t.clob_with_json_file
                 , '$'
                   columns
                   ( c1,
                     c2,
                     NESTED c3 COLUMNS (a),
                     NESTED c4.c5 COLUMNS (c6)
                   )
                 ) tabj
 where t.id = 1; -- just one row in t table

问题是我得到了不止一行:

c1 c2 a c6
c1 c2 a
c1 c2 c6

我需要一排:

c1 c2 a c6
c1 c2 a c6
oracle nested json-table
1个回答
0
投票

您似乎不需要使用

NESTED
,而是使用路径直接引用后代属性:

select tabj.*
from   table_with_clob_column t
       CROSS APPLY JSON_TABLE(
         t.clob_with_json_file,
         '$'
         columns(
           c1,
           c2,
           a PATH '$.c3.a',
           c6 PATH '$.c4.c5.c6'
        )
      ) tabj
where t.id = 1

对于样本数据:

CREATE TABLE table_with_clob_column (
  id NUMBER,
  clob_with_json_file CLOB CHECK (clob_with_json_file IS JSON)
);

INSERT INTO table_with_clob_column (id, clob_with_json_file)
VALUES (1, '{ "c1": "c1", "c2": "c2", "c3": { "a": "a" }, "c4": { "c5": { "c6": "c6" } } }');

输出:

C1 C2 A C6
c1 c2 a c6

小提琴

© www.soinside.com 2019 - 2024. All rights reserved.