SQL中的萬用字元

2021-09-28 22:42:32 字數 834 閱讀 1268

sql中可以使用萬用字元來搜尋資料庫中的資料,萬用字元可用於替代字串中的任意字元。

萬用字元可以配合like操作符一起使用,萬用字元包括:

%的使用

select * from student where name like 'a%';
select * from student where name like '%a%';
select * from student where name like '%a';
_的使用

從student表中選取name字段值以an結尾的資料:

select * from student where name like '_an';
[charlist]的使用

sql中萬用字元可以和like操作符一起使用,但是mysql、sqlite只支援%_萬用字元,會把像like '[***]%'中的中括號當成普通字元,而不是萬用字元。

從student表中選取name欄位以c、t、m開頭的記錄:

select * from student where name regexp '^[ctm]';
從student表中選取name欄位不以a、b開頭的記錄:

select * from student where name regexp '^[^ab]';
參考:

sql中萬用字元的搜尋

sql中有如下萬用字元 含義分別為 包含零個或更多字元的任意字串。下劃線 任何單個字元。指定範圍 例如 a f 或集合 例如 abcdef 內的任何單個字元。不在指定範圍 例如 a f 或集合 例如 abcdef 內的任何單個字元。一般情況,在搜尋框中輸入 下劃線 或者 百分號 然後進行搜尋,由於這...

SQL萬用字元

1.下面的 sql 語句選取 url 以字母 https 開始的所有 2.下面的 sql 語句選取 url 包含模式 oo 的所有 select from websites where url like oo 3.下面的 sql 語句選取 name 以 g 開始,然後是乙個任意字元,然後是 o 然後...

SQL萬用字元

表結構描述 當前有一張表,此處假定node info,存在乙個欄位node path是由 字母 數字 及 下劃線 組成,如 abc 1 de f。需求 查詢所有node path以 abc 開頭的記錄 這個問題,自然而然的就想到,很簡單,直接like 模糊匹配就ok sql view plain c...