在数据库中,SUBSTR函数用于提取字符串的一部分。它的用法如下:
SUBSTR(string, start_position, length)
参数说明:
string:要提取的字符串。start_position:开始提取的位置。索引从1开始。length:要提取的字符长度。示例:假设有一个名为"customers"的表,其中包含一个名为"full_name"的列,存储着客户的全名。
SELECT SUBSTR(full_name, 1, 5) AS first_nameFROM customers;
上述示例中,SUBSTR函数提取了"full_name"列的前5个字符,并将其命名为"first_name"。
结果示例:±------------+| first_name |±------------+| John || Emily || Michael || Sarah |±------------+

