如何在MYSQL中用空字符串替换最后一个子字符串?我在MYSQL中找不到任何这样的直接函数
字符串: "American Corp National Corp"
搜索字符串: "Corp"
预期产量: "American Corp National"
谁有人建议?
这是更短,更易读:
SELECT TRIM(TRAILING 'Corp' FROM 'American Corp National Corp')
Run Code Online (Sandbox Code Playgroud)
小智 2
尝试:
select reverse(concat(
left(reverse('American Corp National Corp'),
instr(reverse('American Corp National Corp'),reverse('Corp'))-1),
substr(reverse('American Corp National Corp'),
instr(reverse('American Corp National Corp'),reverse('Corp'))+
length('Corp')))) result
Run Code Online (Sandbox Code Playgroud)
( SQLFiddle )