與字串的 一部分 比較(LIKE)

2021-08-23 15:15:02 字數 898 閱讀 7971

與 字串的 一部分 進行 比較,使用 like 演算子。

[table]

|[not] like 檢索字串 [escape '轉義字元']|檢索 與 檢索字串 部分地匹配的 記錄。

[/table]

例1)檢索 其列[job_name]以 "job" 字串 開頭的 記錄(使用 "%" 萬用字元)

select * 

from employees

where

job_name like 'job%'

萬用字元"%", 匹配 乙個字元以上的 任意的 字串

例2)檢索 其列[job_name]以 "job" 字串 開頭的 記錄(使用 "_" 萬用字元)

select * 

from employees

where

job_name like 'job_'

萬用字元"_",匹配任意的 乙個字元。

例3)檢索 其列[job_name] 不以 "job" 字串 開頭的 記錄。

select * 

from employees

where

job_name not like 'job%'

例4) 檢索 其列以"job%" 字串 結尾的 記錄。

select * 

from employees

where

job_name like '%job\%' escape '\'

如果 在escape句中 指定 轉義字元(上例為 "\"),則 含有 萬用字元("%", "_")的字串,也可以 被指定為 檢索字串。

字串一部分習題訓練

1.在字串中指定開始位置插入字串 include include include int main for i 0 i lenth2 i printf s n str1 return 0 2.幾個字串求出最小串 include include include int main printf how ...

列印字串的任意一部分

使用printf 函式列印字串的任意部分,請看下例 include include include int main 輸出結果為 first 11 characters this is the last 13 characters source string 在上例中,第一次呼叫printf 函式時...

一部分字符集

charset 描述us ascii 7 位 ascii 字元,也叫作 iso646 us unicode 字符集的基本拉丁塊 iso 8859 1 iso 拉丁字母表 no.1,也叫作 iso latin 1 utf 8 8 位 ucs 轉換格式 utf 16be 16 位 ucs 轉換格式,bi...