SQLite substring() 函数使用指南

来源:这里教程网 时间:2026-03-25 17:20:39 作者:

SQLite

substring()
函数从一个指定的字符串中根据指定的起始位置和长度提取子字符串并返回。

从 SQLite 3.34 开始,

substring()
函数是
substr()
的别名。

substring()
语法

这是 SQLite

substring()
函数的语法:

substring(string, start[, length])

参数

string
必需的。 一个字符串。
start
必需的。 子字符串的起始位置。
length
可选的。 子字符串的长度。默认是提取到字符串的结尾。

返回值

SQLite

substring()
函数从字符串
string
中提取从位置
start
开始且长度为
length
的子字符串并返回。若没有指定参数
length
,则提取从
start
开始到字符串
string
的结尾的子字符串。

如果

start + length
超过了字符串
string
的长度,则返回
start
到字符串的结尾
string
的子字符串。

若参数为

NULL
,该函数将返回
NULL

substring()
示例

这个示例说明了如果使用

substring()
函数在一个字符串中提取从位置 7 开始的字符串。

SELECT substring('hello world', 7);

substring('hello world', 7)---------------------------world

您还可以指定提取的字符数(子字符串的长度),例如:

SELECT substring('hello world', 7, 5);

substring('hello world', 7, 5)------------------------------world

相关推荐

热文推荐