Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

PostgreSQL LIKE 运算符


LIKE

WHERE 子句中使用 LIKE 运算符来搜索列中指定的模式。

通常与 LIKE 运算符结合使用两种通配符

  • % 百分号表示零个、一个或多个字符
  • _ 下划线表示一个字符

以…开头

要返回以特定字母或短语开头的记录,请在字母或短语末尾添加 %

示例

返回所有以字母“A”开头的客户名称

SELECT * FROM customers
WHERE customer_name LIKE 'A%';
运行示例 »

包含

要返回包含特定字母或短语的记录,请在字母或短语前后都添加 %

示例

返回所有包含字母“A”的客户名称

SELECT * FROM customers
WHERE customer_name LIKE '%A%';
运行示例 »

ILIKE

注意: LIKE 运算符区分大小写,如果要进行不区分大小写的搜索,请改用 ILIKE 运算符。

示例

返回所有包含字母“A”或“a”的客户名称

SELECT * FROM customers
WHERE customer_name ILIKE '%A%';
运行示例 »

以…结尾

要返回以特定字母或短语结尾的记录,请在字母或短语之前添加 %

示例

返回所有以“en”结尾的客户名称

SELECT * FROM customers
WHERE customer_name LIKE '%en';
运行示例 »

下划线 _ 通配符

_ 通配符表示单个字符。

可以是任何字符或数字,但每个 _ 表示一个且仅一个字符。

示例

返回所有来自以“L”开头,后面跟着一个通配符,然后是“nd”,最后是两个通配符的城市的客户

SELECT * FROM customers
WHERE city LIKE 'L_nd__';
运行示例 »

PostgreSQL 练习

通过练习测试自己

练习

编写正确的 SQL 语句,以选择 model 字段的值以大写字母“M”开头的所有记录。

SELECT * FROM cars
WHERE model ;
        

开始练习


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.