简体   繁体   中英

Weird FOR ORDINALITY column behavior for json_table query with nested path in Oracle 12.1

I have a JSON text in a clob:

[
  {
    "debitOverturn": "939.34",
    "table": [
      {
        "debit": "",
        "credit": "939.34"
      },
      {
        "debit": "939.34",
        "credit": ""
      }
    ]
  },
  {
    "debitOverturn": "939.34",
    "table": [
      {
        "debit": "",
        "credit": "939.34"
      },
      {
        "debit": "939.34",
        "credit": ""
      }
    ]
  }
]

trying to query it on oracle 12.1:

SELECT jt.u_lvl,
       jt.debitOverturn,
       jt.l_lvl,
       jt.debit,
       jt.credit
 FROM test1 s,
     JSON_TABLE (s.json_data,'$[*]' COLUMNS (
        u_lvl FOR ORDINALITY,
        debitOverturn VARCHAR2(20) PATH '$.debitOverturn',
        NESTED PATH '$.table[*]'
            COLUMNS (
                l_lvl FOR ORDINALITY,
                debit VARCHAR2(38) PATH '$.debit',
                credit VARCHAR2(38) PATH '$.credit'))) AS jt
   WHERE s.id = 1;

and see some weird result in u_lvl column:

U_LVL   DEBITOVERTURN   L_LVL   DEBIT   CREDIT
1   939.34  1   (null)  939.34
2   939.34  2   939.34  (null)
3   939.34  1   (null)  939.34
4   939.34  2   939.34  (null)

It looks like FOR ORDINALITY column counts all rows in the query instead of rows at its level. So I tried to rerun task at my home VM server with Oracle 12.2 and got different (and much more reliable) result:

U_LVL   DEBITOVERTURN   L_LVL   DEBIT   CREDIT
1   939.34  1   (null)  939.34
1   939.34  2   939.34  (null)
2   939.34  1   (null)  939.34
2   939.34  2   939.34  (null)

Then I tried to run the same query at Oracle Livesql server (livesql.oracle.com) and got another result:

U_LVL   DEBITOVERTURN   L_LVL   DEBIT   CREDIT
1   939.34  1   (null)  939.34
1   939.34  2   939.34  (null)
1   939.34  1   (null)  939.34
1   939.34  2   939.34  (null)

Is that an Oracle bug? Or the difference between major DB releases? Is FOR ORDINALITY behaviour can be adjusted in some deep DB settings?

This is a known bug in the JSON_TABLE function in 12.1. If you can't upgrade to 12.2 a patch is available, but you'll have to have a support account to get it.

Further details are on the Oracle support site, in Doc ID 2301973.1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM