共用方式為


字串標準函式 (Entity SQL)

實體 SQL 包含字串標準函式。

備註

下表將顯示字串 實體 SQL 標準函式。

函式 描述

Concat (string1, string2)

傳回包含附加至 string1 之 string2 的字串。

引數

String

傳回值

String。如果傳回值字串的長度超過允許的最大長度,就會發生錯誤。

範例

-- The following example returns abcxyz.

Concat('abc', 'xyz')

IndexOf(string1, string2)

傳回 string1 在 string2 內部的位置,或 0 (如果找不到的話)。傳回 1 是表示字串的開頭。索引編號會從 1 開始。

引數

String

傳回值

Int32

範例

-- The following example returns 4.

IndexOf('xyz', 'abcxyz')

Left (string, length)

從 string 的左側傳回前 length 個字元。如果 string 的長度小於 length,就會傳回整個字串。

引數

string:String

length:Int16Int32Int64Byte。length 不得小於零。

傳回值

String

範例

-- The following example returns abc.

Left('abcxyz', 3)

Length (string)

傳回字串的 (Int32) 長度 (以字元為單位)。

引數

string:String

傳回值

Int32

範例

-- The following example returns 6.

Legth('abcxyz')

LTrim(string)

傳回不含前置空白字元的 string。

引數

String

傳回值

String

範例

-- The following example returns abc.

LTrim(' abc')

Replace (string1, string2, string3)

傳回 string1,並將 string2 的所有相符項目取代成 string3。

引數

String

傳回值

String

範例

-- The following example returns abcxyz.

Concat('abc', 'xyz')

Reverse (string)

使用反向字元的順序傳回 string。

引數

String

傳回值

String

範例

-- The following example returns dcba.

Reverse('abcd')

Right (string, length)

從 string 中傳回最後 length 個字元。如果 string 的長度小於 length,就會傳回整個字串。

引數

string:String

length:Int16Int32Int64Byte。length 不得小於零。

傳回值

String

範例

-- The following example returns xyz.

Right('abcxyz', 3)

RTrim(string)

傳回不含尾端空白字元的 string。

引數

String

傳回值

String

Substring (string, start, length)

從位置 start 開始傳回字串的子字串,而且長度為 length 個字元。start 為 1 是表示字串的第一個字元。索引編號會從 1 開始。

引數

string:String

start:Int16Int32Int64Byte。start 不得小於一。

length:Int16Int32Int64Byte。length 不得小於零。

傳回值

String

範例

-- The following example returns xyz.

Substring('abcxyz', 4, 3)

ToLower(string)

傳回將大寫字元轉換成小寫的 string。

引數

String

傳回值

String

範例

-- The following example returns abc.

ToLower('ABC')

ToUpper(string)

傳回將小寫字元轉換成大寫的 string。

引數

String

傳回值

String

範例

-- The following example returns ABC.

ToUpper('abc')

Trim(string)

傳回不含前置和尾端空白字元的 string。

引數

String

傳回值

String

範例

-- The following example returns abc.

Trim(' abc ')

如果提供 Null 輸入,這些函式會傳回 Null

Microsoft SQL Client Managed Provider 中提供了對等的功能。如需詳細資訊,請參閱 適用於 Entity Framework 的 .NET Framework Data Provider for SQL Server (SqlClient) 函式

另請參閱

概念

標準函式 (Entity SQL)