mysql - 如何在 MySQL 中的字符串中提取字符串
问题描述
我有一个字符串值:
'{"CUSTOMER_TOPUP":{"bankname":"45","amount":"1000","depositreference":"REF1111"}}'
并想返回值:REF1111
这是我的 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'
))
推荐阅读
- jqgrid - jqgrid 在编辑或添加表单时未显示任何字段
- kubernetes - 如果节点变为离线超时,Kubernetes 会重新创建 pod
- excel-formula - 使用带有通配符的 excel vlookup
- javascript - Magento 2 - 来自 Javascript 的请求返回状态码 302
- kubernetes - 将相关容器托管在节点上,避免网络访问成本
- powershell - 在 Powershell 中替换包含引号的字符串
- c# - 实现静态方法的最佳实践
- teradata - Teradata 以数字格式导出时间结果
- mysql - 如何从不同的列中选择最旧的日期?
- javascript - 实现 UI 后 p5.js 草图不起作用