Oracle截取JSON字符串內容


 1 CREATE OR REPLACE FUNCTION PLATFROM.parsejsonstr(p_jsonstr varchar2,startkey varchar2,endkey varchar2) RETURN VARCHAR2
 2 IS
 3   rtnVal VARCHAR2(1000);
 4   FindIdxS NUMBER(2);
 5   FindIdxE NUMBER(2);
 6 BEGIN
 7 if endkey='}' then
 8     rtnVal:=substr(p_jsonstr,(instr(p_jsonstr,startkey)+length(startkey)  +2)
 9         ,(instr(p_jsonstr,endkey,instr(p_jsonstr,startkey))-instr(p_jsonstr,startkey)-length(startkey)-2));
10 else
11     rtnVal:=substr(p_jsonstr,(instr(p_jsonstr,startkey)+length(startkey)  +2)
12         ,(instr(p_jsonstr,endkey,instr(p_jsonstr,startkey))-instr(p_jsonstr,startkey)-length(startkey)-4));
13 end if;
14   RETURN rtnVal;
15 END parsejsonstr;
16 /

 參數說明:

    p_jsonstr:目標JSON字符串

    startkey:需要截取的JSON內容key值

    endkey:目標key的下一個key

 

  舉例說明:select parsejsonstr(INFO,'AGE', 'HEIGHT') from TTTT

    圖為TTTT表中的內容,例子為截取INFO中的AGE信息。

      

 

 

 

 

        


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM