SQL MID() 使用实例教程
mid( )函数
mid( )函数是用来提取字符的文本字段。
数据库mid( )语法
SELECT MID(column_name,start[,length]) FROM table_name
Parameter | Description |
---|
column_name | Required. The field to extract characters from. |
start | Required. Specifies the starting position (starts at 1). |
length | Optional. The number of characters to return. If omitted, the MID() function returns the rest of the text. |
来看个实例吧.
| LastName | FirstName | Address | City |
---|
1 | Hansen | Ola | Timoteivn 10 | Sandnes |
2 | Svendson | Tove | Borgvn 23 | Sandnes |
3 | Pettersen | Kari | Storgt 20 | Stavanger |
现在,我们要提取的前四个字符的“城市”专栏以上。
我们使用下面的SELECT语句:
SELECT MID(City,1,4) as SmallCity FROM Persons
结果.