是否可以在子字符串函数中使用字符而不是位置?
是否可以在子字符串函数中使用字符而不是位置?
SELECT SUBSTRING(title,2) FROM table
puts out every title starting with the second position.现在我想在空格后剪切输出。空间位置各不相同。 可以实现吗?
我尝试过某事。喜欢
SUBSTRING(title,2,LOCATE('',title))
,but for some reason the output was empty.先感谢您。 索洛科
is it possible to use characters instead of a position in a substring function?
SELECT SUBSTRING(title,2) FROM table
puts out every title starting with the second position.
Now I want to cut the output after a space. The space positions varies.
Is it realiseable?
I tried sth. like
SUBSTRING(title,2,LOCATE('',title))
,but for some reason the output was empty.
Thank you in advance.
Soloco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 SUBSTRING_INDEX 来实现:
http://dev.mysql.com/doc/refman/5.0/en/string-functions.htm
You can use
SUBSTRING_INDEX
for that:http://dev.mysql.com/doc/refman/5.0/en/string-functions.htm
在 LOCATE 语句中,您要搜索空字符串
''
而不是空格' '
添加空格字符。
您所做的操作将从字符串的第二个字符到第一次出现的空格字符之间获取字符串。这真的是你想做的吗?如果第一个或第二个字符是空格字符怎么办?
In your LOCATE statement, you are searching for an empty string
''
instead of a space' '
Add a space character.
What you are doing will fetch the string from its second character to the first occurrence of a space character. Is this really what you want to do? What if the the first or second character are space characters?
您可以使用:
这会在标题中的空格之前剪切字符串
You could use:
This would cut the string just before the space in the title