救命啊!
我正在尝试将下面的字符串修剪到中间部分“Lync女士”
“系统和应用程序->MS Lync->更改请求”
我试过下面的查询,但仍然得到特殊字符。字符串长度会改变,但特殊字符不会:

LEFT(probcodedesc, CHARINDEX('-', probcodedesc)) AS Area,
substring(probcodedesc, charindex('> ',probcodedesc),charindex('> ', probcodedesc, charindex('>', probcodedesc) - charindex(' ->', probcodedesc))) as Category,
RIGHT(probcodedesc, CHARINDEX('>', REVERSE(probcodedesc))) AS Event

感谢所有的帮助和建议!

最佳答案

我会用niftySUBSTRING_INDEX函数来做这样的事情。
参考:https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_substring-index
例如:

SET @s = 'Systems & Apps -> MS Lync -> Request for Change';

SELECT TRIM(SUBSTRING_INDEX(@s,'->',1)) AS `Area`

Area
----------------
Systems & Apps


SELECT TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(@s,'->',-2),'->',1)) AS `Category`

Category
---------
MS Lync


SELECT TRIM(SUBSTRING_INDEX(@s,'->',-1)) AS `Event`

Event
------------------
Request for Change

08-26 08:19