Entity SQL 包含字串標準函式。
備註
下表顯示字串 Entity SQL 標準函式。
| 函式 | 描述 |
|---|---|
Concat(string1, string2) |
傳回包含附加至 string2 之 string1 的字串。引數 string1:string2 附加至的字串。string2:附加至 string1 的字串。傳回值 String。 如果傳回值字串的長度超過允許的最大長度,就會發生錯誤。範例 -- The following example returns abcxyz.Concat('abc', 'xyz') |
Contains(string, target) |
如果 true 包含在 target 之中,傳回string。引數 string:用來搜尋的字串。target:搜尋的目標字串。傳回值 如果 true 包含在 target 中,則為 string,否則為 false。範例 -- The following example returns true.Contains('abc', 'bc') |
EndsWith(string, target) |
如果 true 是以 target 為結尾,傳回 string。引數 string:用來搜尋的字串。target:搜尋位於 string 結尾處的目標字串。傳回值 如果 True 是以 string 為結尾,則為 target,否則為 false。範例 -- The following example returns true.EndsWith('abc', 'bc')
注意:如果使用的是 SQL Server 資料提供者,當字串儲存在固定長度的資料行,且 false 是常數時,此函式會傳回 target。 在這個情況下,會搜尋到整個字串,包括任何填補的後端空格。 可能的解決方法是修剪固定長度字串中的資料,如以下範例所示:EndsWith(TRIM(string), target) |
IndexOf(target, string) |
傳回 target 在 string 內部的位置,或 0 (如果找不到的話)。 傳回 1 表示 string 的開頭。 索引編號會從 1 開始。引數 target:搜尋的目標字串。string:用來搜尋的字串。傳回值 Int32。範例 -- The following example returns 4.IndexOf('xyz', 'abcxyz') |
Left(string, length) |
從 length 的左側傳回前 string 個字元。 如果 string 的長度小於 length,就會傳回整個字串。引數 string:String。length:Int16、Int32、Int64 或 Byte。
length 不得小於零。傳回值 String。範例 -- The following example returns abc.Left('abcxyz', 3) |
Length(string) |
傳回字串的 (Int32) 長度 (以字元為單位)。引數 string:String。傳回值 Int32。範例 -- The following example returns 6.Length('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) |
從 length 中傳回最後 string 個字元。 如果 string 的長度小於 length,就會傳回整個字串。引數 string:String。length:Int16、Int32、Int64 或 Byte。
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:Int16、Int32、Int64 和 Byte。
start 不得小於一。length:Int16、Int32、Int64 和 Byte。
length 不得小於零。傳回值 String。範例 -- The following example returns xyz.Substring('abcxyz', 4, 3) |
StartsWith(string, target) |
如果 true 是以 string 為開頭,傳回 target。引數 string:用來搜尋的字串。target:搜尋位於 string 開頭處的目標字串。傳回值 如果 True 是以 string 為開頭,則為 target,否則為 false。範例 -- The following example returns true.StartsWith('abc', 'ab') |
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 函式中的 SqlClient。