目录

SQL服务器 CHARINDEX() 函数

示例

在字符串"Customer"中搜索"t",并返回位置:

SELECT CHARINDEX('t', 'Customer') AS MatchPosition;
亲自试一试 »

定义和用法

CHARINDEX() 函数在字符串中搜索子字符串,并返回位置。

如果未找到子字符串,该函数返回 0。

笔记:该函数执行不区分大小写的搜索。

语法

CHARINDEX( substring, string, start)

参数值

Parameter Description
substring Required. The substring to search for
string Required. The string to be searched
start Optional. The position where the search will start (if you do not want to start at the beginning of string). The first position in string is 1

技术细节

工作于: SQL Server(从 2008 年开始)、Azure SQL 数据库、Azure SQL 数据仓库、并行数据仓库

更多示例

示例

在字符串"Customer"中搜索"OM",并返回位置:

SELECT CHARINDEX('OM', 'Customer') AS MatchPosition;
亲自试一试 »

示例

在字符串 "Customer" 中搜索 "mer",并返回位置(从位置 3 开始):

SELECT CHARINDEX('mer', 'Customer', 3) AS MatchPosition;
亲自试一试 »