【www.gdgbn.com--php函数】

SQL MID() 使用实例教程

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

数据库mid( )语法

SELECT MID(column_name,start[,length]) FROM table_name
ParameterDescriptioncolumn_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.
来看个实例吧.
 LastNameFirstNameAddressCity1HansenOlaTimoteivn 10Sandnes2SvendsonToveBorgvn 23Sandnes3PettersenKariStorgt 20Stavanger

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

我们使用下面的SELECT语句:

SELECT MID(City,1,4) as SmallCity FROM Persons
结果.
SmallCitySandSandStav

本文来源:http://www.gdgbn.com/jiaocheng/17417/