日期:2014-05-16  浏览次数:21086 次

mysql字符串函数,删除首位字符串

如字段为 so.go.lie 查询上一级的方法为:ed,(reverse(substring_index(reverse(ed),'.',1))),'')

?

删除最后一个字符串的方法:

  1. LEFT(XXX,LENGTH(XXX)-1)
  2. SUBSTRING(XXX, 1,length(XXX)-1)
  3. TRIM(TRAILING ',' FROM XXX)

?

?

?

trim函数可以过滤指定的字符串:
完整格式:TRIM([{BOTH?|?LEADING?|?TRAILING}?[remstr]?FROM]?str)
简化格式:TRIM([remstr?FROM]?str)

Returns?the?string?str?with?all?remstr?prefixes?or?suffixes?removed.?If?none?of?the?specifiers?BOTH,?LEADING,?or?TRAILING?is?given,?BOTH?is?assumed.?remstr?is?optional?and,?if?not?specified,?spaces?are?removed.

以下是代码片段:

1
2
3
4
5
6
7
8
mysql>?SELECT?TRIM('?bar???');?//默认删除前后空格
->?'bar'
mysql>?SELECT?TRIM(LEADING?','?FROM?',,barxxx');????//删除指定首字符?如’,‘
->?'barxxx'
mysql>?SELECT?TRIM(BOTH?','?