sql statement to add custom functions getJsonValue

Performed at sql statement execution region, to add functions, belonging to parameter format getJsonValue ( 'field contains the name json', corresponding to the field name strings json)

CREATE FUNCTION `getJsonValue`(pKeyName VARCHAR(64),pColName mediumtext) RETURNS varchar(2000) CHARSET utf8 COLLATE utf8_bin
return 
substr(pColName,
locate(concat('"',upper(pKeyName),'":"'),upper(pColName))+length(concat('"',upper(pKeyName),'":"')),
case when locate('","',substr(upper(pColName),locate(concat('"',upper(pKeyName),'":"'),upper(pColName))))>0 then (locate('","',substr(upper(pColName),locate(concat('"',upper(pKeyName),'":"'),upper(pColName))+length(concat('"',upper(pKeyName),'":"'))))-1)
else locate('"}',substr(upper(pColName),locate(concat('"',upper(pKeyName),'":"'),upper(pColName))+length(concat('"',upper(pKeyName),'":"'))))-1 end )

Guess you like

Origin blog.csdn.net/John_Kry/article/details/87976430