两个字符串之间的MySQL子字符串 [英] MySQL substring between two strings

查看:399
本文介绍了两个字符串之间的MySQL子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助解决我的栏位问题. 我需要提取这两个不同的字符串模式"之间的字符串,例如:

I need a hand to solve a problem with my column field. I need to extract the string in between these two different "patterns" of strings for example:

[... string]合约= 1234567890123350566076070666已发布= [string ...]

[...string] contract= 1234567890123350566076070666 issued= [string ...]

我想提取介于'contract ='和'issued ='之间的字符串

I want to extract the string in between 'contract=' and 'issued='

目前我正在使用

SELECT substring(substring_index(licence_key,'contract=',-1),1,40) FROM table

问题在于,此字符串之间的字符串并不总是40个字符,因此它的长度不是固定的,因此前后的数据均不固定.这是易变的数据.

The problem is that this string in between doesn't have always 40 characters so it's not fixed length and so the data that comes before and after that. It's a volatile data.

你知道我该怎么办吗?

推荐答案

只需两次使用substring_index():

SELECT substring_index(substring_index(licence_key, 'contract=', -1),
                       'issued=', 1)
FROM table;

这篇关于两个字符串之间的MySQL子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆