如何使用plsql从List中提取行数据?

问题描述 投票:0回答:1
SELECT JSON_QUERY(A.RESPONSEXML,
'$.banking_info.ccris_banking_details.outstanding_credit.items[*].subAccount.subAccountItem.subAccountItem1.credit_position.items'
WITH ARRAY WRAPPER)
  FROM RAMCI_RESPONSE A
 WHERE A.APPID = '5004505'
   AND ROWNUM = 1;



 DBMS_OUTPUT.PUT_LINE(ITEMSDATA);

END.这是我从上述查询中提取数据后得到的字符串。

这是我从上面的查询中提取数据后得到的字符串。

[["","","2","1","1","1","1","0","0","0","0","0"],["","","0","0","0","1","2","3","2","0","0","0"],["","","0","0","1","2","2","1","1","1","2","0"],["","","0","0","0","1","2","2","2","1","0","0"]]

我们如何才能得到行的数据?

oracle plsql plsqldeveloper
1个回答
0
投票

你可以使用如下的层次结构查询。

SQL> with dataa (d) as
  2  (select '[["","","2","1","1","1","1","0","0","0","0","0"],["","","0","0","0","1","2","3","2","0","0","0"],["","","0","0","1","2","2","1","1","1","2","0"],["","","0","0","0","1","2","2","2","1","0","0"]]' from dual)
  3  -- query starts from here
  4  select '[' || ltrim(ltrim(regexp_substr(d,'[^]]+',1,level) || ']',','),'[') as str
  5  from dataa
  6  connect by level <= regexp_count(d,'\[') - 1;

STR
--------------------------------------------------------------------------------
["","","2","1","1","1","1","0","0","0","0","0"]
["","","0","0","0","1","2","3","2","0","0","0"]
["","","0","0","1","2","2","1","1","1","2","0"]
["","","0","0","0","1","2","2","2","1","0","0"]

SQL>

-- 更新。

SQL> with dataa (d) as
  2  (select '[["","","2","1","1","1","1","0","0","0","0","0"],["","","0","0","0","1","2","3","2","0","0","0"],["","","0","0","1","2","2","1","1","1","2","0"],["","","0","0","0","1","2","2","2","1","0","0"]]' from dual)
  3  -- query starts from
  4  SELECT COALESCE(SUM(CASE WHEN CNTR > 1 THEN 1 END),0) AS CNTR
  5  FROM
  6  (SELECT T.STR, REGEXP_SUBSTR(T.STR, '[0-9]+',1,COLUMN_VALUE) AS CNTR FROM
  7  (select LTRIM(regexp_substr(d,'[^]]+',1,level),',') as str
  8  from dataa
  9  connect by level <= regexp_count(d,'\[') - 1) T
 10  CROSS JOIN
 11  table(cast(multiset(select level from dual
 12  connect by  level <= length (regexp_replace(t.STR, '[^,]+'))  + 1)
 13  as sys.OdciNumberList)) levels);

      CNTR
----------
        10

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