如何在MySQL中提取字符串中的字符串



我有一个字符串值:

'{"CUSTOMER_TOPUP":{"bankname":"45","amount":"1000","depositreference":"REF1111"}}'

并且希望返回值:参考文献1111

这是我Json字符串的最后一部分。

请注意,我的字符串可以有不同的值。例如:

'{"BILLPAYMENT":{"utility":"11","amount":"50","accountnumber":"123456"}}' 

我需要返回值字符串123456

我严格使用Mysql来创建自己的函数。

为什么不使用JSON函数?

json_extract(
'{"CUSTOMER_TOPUP":{"bankname":"45","amount":"1000","depositreference":"REF1111"}}',
'$.CUSTOMER_TOPUP.depositreference'
)

或者,如果你想去掉结果值周围的双引号:

json_unquote(json_extract(
'{"CUSTOMER_TOPUP":{"bankname":"45","amount":"1000","depositreference":"REF1111"}}',
'$.CUSTOMER_TOPUP.depositreference'
))

最新更新