SQL Server 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データウェアハウス、Parallel Data Warehouse |
---|
その他の例
例
文字列「Customer」で「OM」を検索し、位置を返します。
SELECT
CHARINDEX('OM', 'Customer') AS MatchPosition;
例
文字列「Customer」で「mer」を検索し、位置を返します(位置3から開始)。
SELECT CHARINDEX('mer', 'Customer', 3) AS MatchPosition;