如何在MySQL中删除部分字符串?

Mik*_*zer 3 mysql sql select

在MySQL中,我有一个文本列,其中包含"bla bla bla YYY = 76767 bla bla bla".

我需要减少76767的数量.

我怎么能在SQL中做到这一点?

Den*_*ret 5

您可以使用

select substring_index(substring(mycol, instr(mycol, "=")+1), " ", 1)
Run Code Online (Sandbox Code Playgroud)

在获得第一个令牌之后=.

这回来了 76767.


这有两个步骤:

substring(mycol, instr(mycol, "=")+1)
Run Code Online (Sandbox Code Playgroud)

返回后面的字符串 =

substring_index( xxx , " ", 1)
Run Code Online (Sandbox Code Playgroud)

通过""获取您从拆分中得到的虚拟阵列的第一个元素,因此返回xxx的第一个标记.