Skip to content
All writing Part 05 of 09 · [object Object]
Engineering · 1 min read

LIKE 與 ILIKE:SQL 引擎裡的子字串搜尋

SQL 的子字串搜尋:LIKE 與 ILIKE 怎麼運作、% 與 _ 萬用字元、跳脫,以及同一個操作如何對應到 MongoDB 的 $regex($options: 'i')。

「在一段字串裡找子字串」是最常見的 operation 之一。SQL 引擎用 LIKE / ILIKE 加上 pattern 來做。

string LIKE/ILIKE pattern

  • 回傳「string 是否符合 LIKE 的 pattern」
    • string LIKE patternstring NOT ILIKE pattern
    • 差別:ILIKE不分大小寫(case-insensitive)。

pattern 規則

  • %:任意數量的任意字元(含零個)。
  • _:單一個任意字元。
  • \:跳脫字元,用來比對字面上的 %_\
  • 例:%minor_action_hr%

對照到 Mongo,這個 operation 是 $regex$options: "i" 等於 ILIKE)→ MongoDB 運算子與詞彙對照


參考來源

Related: 回到跨引擎資料庫查詢總覽,或在可攜式 SQL 核心裡看它的定位。

Tags #sql #databases
// connect

Be brave | Be wise | Be grateful

21 BreakinCode

// elsewhere
LinkedInMedium (lang: en)Youtube
wh:~$William Hung· © 2026 Taipei · GMT+8 · Available for collaboration