Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

將字串運算式與 SQL 運算式中的模式做比較。

語法

expression Likepattern

Like 運算子語法由下列各部分組成:

部分

描述

expression

WHERE 子句中使用的 SQL 運算式。

pattern

用來與 expression 比較的字串或字元字串文字。


備註

您可以使用 Like 運算子在欄位中尋找符合您指定之模式的值。 針對 pattern,您可以指定完整值 (例如 Like “Smith”),或者您可以使用萬用字元尋找值範圍 (例如 Like “Sm*”))。

在表達式中,您可以使用 Like 運算符來比較域值與字串表達式。 例如,如果您在 SQL 查詢中輸入 Like “C*” ,查詢會傳回以字母 C 開頭的所有域值。在 參數查詢中,您可以提示使用者輸入要搜尋的模式。

以下範例會傳回開頭為字母 P,後面接著 A 到 F 之間的任何字母和三位數的資料:

Like “P[A-F]###”

下表顯示如何使用 Like 測試運算式的不同模式。


符合種類


模式

符合
(傳回 True)

不符合
(傳回 False)

多個字元

a*a

aa, aBa, aBBBa

aBC

*ab*

abc, AABB, Xab

aZb, bac

特殊字元

a[*]a

a*a

aaa

多個字元

ab*

abcdefg, abc

cab, aab

單一字元

a?a

aaa, a3a, aBa

aBBBa

單一數字

a#a

a0a, a1a, a2a

aaa, a10a

字元範圍

[a-z]

f, p, j

2, &

範圍以外

[!a-z]

9, &, %

b, a

非數字

[!0-9]

A, a, &, ~

0, 1, 9

組合

a[!b-m]#

An9, az0, a99

abc, aj0



Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×