substr mysql_MySQL数据库中substr字符串分隔函数简介说明

摘要:

下文讲述MySQL数据库中substr字符串分隔函数的用法说明,如下所示;

substr字符串分隔函数功能:

substr系统函数的功能:

对字符串进行分隔,并返回分隔后的字符串

substr字符串分隔函数的四种语法形式:

str:待分隔字符串

pos:起始位置

len:截取长度

substr(str,pos)

从pos开始截取字符串,直到结尾

substr(str,pos,len)

从pos开始截取字符串,

共截取len位

substr(str from pos)

同substr(str,pos)相同

substr(str from pos for len)

同substr(str,pos,len)相同

注意事项:

1.pos值不可以为零,pos为0时,返回空字符串

2.len值小于等于0时,则返回空字符串

3.pos为负数时,则从右边数字符串的开始位置

例:

mysql> select substr('maomao365.com',0);

+---------------------------+

| substr('maomao365.com',0) |

+---------------------------+

| |

+---------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',1);

+---------------------------+

| substr('maomao365.com',1) |

+---------------------------+

| maomao365.com |

+---------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',2);

+---------------------------+

| substr('maomao365.com',2) |

+---------------------------+

| aomao365.com |

+---------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',-1);

+----------------------------+

| substr('maomao365.com',-1) |

+----------------------------+

| m |

+----------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',-2);

+----------------------------+

| substr('maomao365.com',-2) |

+----------------------------+

| om |

+----------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',-2,10);

+-------------------------------+

| substr('maomao365.com',-2,10) |

+-------------------------------+

| om |

+-------------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',2,10);

+------------------------------+

| substr('maomao365.com',2,10) |

+------------------------------+

| aomao365.c |

+------------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com',0,10);

+------------------------------+

| substr('maomao365.com',0,10) |

+------------------------------+

| |

+------------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com' from 3);

+--------------------------------+

| substr('maomao365.com' from 3) |

+--------------------------------+

| omao365.com |

+--------------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com' from 3 for 10);

+---------------------------------------+

| substr('maomao365.com' from 3 for 10) |

+---------------------------------------+

| omao365.co |

+---------------------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com' from 3 for -1);

+---------------------------------------+

| substr('maomao365.com' from 3 for -1) |

+---------------------------------------+

| |

+---------------------------------------+

1 row in set (0.00 sec)

mysql> select substr('maomao365.com' from 3 for 0);

+--------------------------------------+

| substr('maomao365.com' from 3 for 0) |

+--------------------------------------+

| |

+--------------------------------------+

1 row in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值