温馨提示×

怎么在mysql中截取字符串

养鱼的猫咪
388
2021-04-23 08:05:24
栏目: 云计算

mysql中截取字符串的方法:1.使用left函数从左边截取字符串;2.使用right函数从右边截取字符串;3.使用substring函数在指定位置截取字符串;

怎么在mysql中截取字符串

具体方法如下:

1.left函数

mysql中left函数的作用是用于返回具有指定长度字符串的左边部分。

left函数语法:

left(str, length);

参数:

str:指定字符串。

length:需截取字符的长度。

left函数使用方法:

select left('helloworld',5) as result from dual;     //返回 hello

2.right函数

mysql中right函数的作用是用于返回具有指定长度字符串的右边部分。

right函数语法:

right(str, length);

参数:

str:指定字符串。

length:需截取字符的长度。

right函数使用方法:

select right('helloworld',5) as result from dual;     //返回 world

3.substring函数

mysql中substring函数的作用是用于从字符串中提取子字符串。

substring函数语法:

substring(str, pos, length);

参数:

str:指定字符串。

pos:指定截取位置。

length:需截取字符的长度。

substring函数使用方法:

select substring('helloworld',5,4) as result from dual;     //返回 worl


0