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信息。