当前位置:数据库 > MySQL >>

SQL MID() 使用实例教程

SQL MID() 使用实例教程

mid( )函数
mid( )函数是用来提取字符的文本字段。

数据库mid( )语法

SELECT MID(column_name,start[,length]) FROM table_name
ParameterDescription
column_nameRequired. The field to extract characters from.
startRequired. Specifies the starting position (starts at 1).
lengthOptional. The number of characters to return. If omitted, the MID() function returns the rest of the text.
来看个实例吧.
 LastNameFirstNameAddressCity
1HansenOlaTimoteivn 10Sandnes
2SvendsonToveBorgvn 23Sandnes
3PettersenKariStorgt 20Stavanger

现在,我们要提取的前四个字符的“城市”专栏以上。

我们使用下面的SELECT语句:

SELECT MID(City,1,4) as SmallCity FROM Persons
结果.
SmallCity
Sand
Sand
Stav
补充:数据库,mysql教程
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,