SQL MID() ফাংশন

MID() 函数

MID 函数用于从文本字段中提取字符。

SQL MID() 语法

SELECT MID(column_name,start[,length table_name
Parameters Description
column_name Required. The field to extract characters from.
start Required. Specifies the starting position (the starting value is 1).
length Optional. The number of characters to return. If omitted, the MID() function returns the remaining text.

SQL MID() Example

We have the following 'Persons' table:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing

Now, we want to extract the first 3 characters from the 'City' column.

We use the following SQL statement:

SELECT MID(City,1,3) as SmallCity FROM Persons

The result set is similar to this:

SmallCity
Lon
New
Bei