【发布时间】:2014-09-13 11:32:46
【问题描述】:
如何修剪(删除)从字符串右侧到第一个空格的所有字符?
这是我想要做的:
set @s:='May the Gods watch over your battles, my friend!';
select if(length(@s) < 10,@s,left(@s,10)) a;
#output from above: 'May the Go'
#desired output: 'May the'
为了避免像May the Go 这样的奇怪输出,我试图从右边修剪所有字符,直到第一个空格,所以输出是May the。
如何在 sql 语句本身中做到这一点。我找不到可以执行此操作的内置函数?
【问题讨论】: