SUBSTRING() 函数从字符串中提取子字符串(从任意位置开始)。
笔记:这个SUBSTR()和中()函数等于 SUBSTRING() 函数。
SUBSTRING(
string,
start,
length)
或者:
SUBSTRING(
string FROM
start FOR
length)
Parameter | Description |
---|---|
string | Required. The string to extract from |
start | Required. The start position. Can be both a positive or negative number. If it is a positive number, this function extracts from the beginning of the string. If it is a negative number, this function extracts from the end of the string |
length | Optional. The number of characters to extract. If omitted, the whole string will be returned (from the start position) |
工作于: | 从 MySQL 4.0 开始 |
---|
从列中的文本中提取子字符串(从位置 2 开始,提取 5 个字符):
SELECT SUBSTRING(CustomerName, 2, 5) AS ExtractString
FROM Customers;
亲自试一试 »
从字符串中提取子字符串(从末尾开始,在位置-5处,提取5个字符):
SELECT SUBSTRING("SQL Tutorial", -5, 5) AS ExtractString;
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!