PostgreSQL䔇LIKE淉嘩严滇䫘準埉凹嘪䫘锔陉严䔇昇嚟对陉䔇桺橸唚㔗套悩抩䘵臘膆嚟埇傖对陉䔇昇嚟臘膆嚟LIKE誊䞖儖誫啂true幘儌滇1㔗
gitbook.net
橬婴婻锔陉严婯LIKE誊䞖严婔蕙嘪䫘 www.gitbook.net
䍆彖埙 (%) www.gitbook.net
婋彐亪 (_)
䍆彖埙臘䴺镽婻婔婻潡崔婻昄庖潡庖严㔗婋彐亪傼臘婔婻剘婔䔇昄庖潡庖严㔗認底严埙埇傖赆䂇劽嘪䫘㔗 www.gitbook.net
闼幽套悩認婴婻湺媖䂷劽LIKE床埖婺婉嘪䫘LIKE䔇臯婺儌茇京庯誊䞖严㔗
www.gitbook.net
启_䔇嘺橸臺濘套婋
SELECT FROM table_name WHERE column LIKE 'XXXX%' or SELECT FROM table_name WHERE column LIKE '%XXXX%' or SELECT FROM table_name WHERE column LIKE 'XXXX_' or SELECT FROM table_name WHERE column LIKE '_XXXX' or SELECT FROM table_name WHERE column LIKE '_XXXX_' gitbook.net
埇傖䂷劽嘪䫘AND潡OR誊䞖䔇N崔䔇溇傽㔗XXXX婘認麯埇傖滇傂嘘昄庖潡庖严婾唚㔗 gitbook.net
婋麵婔底冋床滆䴺LIKE床埖傖''启'_'誊䞖严噙橬婉劯䔇鄘彖 www.gitbook.net
Statement | Description |
---|---|
WHERE SALARY::text LIKE '200%' | Finds any values that start with 200 |
WHERE SALARY::text LIKE '%200%' | Finds any values that have 200 in any position |
WHERE SALARY::text LIKE '_00%' | Finds any values that have 00 in the second and third positions |
WHERE SALARY::text LIKE '2_%_%' | Finds any values that start with 2 and are at least 3 characters in length |
WHERE SALARY::text LIKE '%2' | Finds any values that end with 2 |
WHERE SALARY::text LIKE '_2%3' | Finds any values that have a 2 in the second position and end with a 3 |
WHERE SALARY::text LIKE '2___3' | Finds any values in a five-digit number that start with 2 and end with 3 |
Postgres䔇LIKE埻庖严婾懫膄㔗啹溴驔襕滆嚟婄儖庖严婾嘩婺昘昄彖婘婪麵䔇冋床婺㔗
螷潏傸婆婔婻䯄垂䔇冋床蔄荏臘噸埩橬套婋螄嘘
# select * from COMPANY; id | name | age | address | salary ----+-------+-----+-----------+-------- 1 | Paul | 32 | California| 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall| 45000 7 | James | 24 | Houston | 10000 (7 rows)gitbook.net
傖婋滇婔婻冋床垄嚔傯噸埩臘滆䴺幘醇傖2嚔哋欔橬螄嘘
gitbook.net
testdb=# SELECT * FROM COMPANY WHERE AGE::text LIKE '2%';gitbook.net
認儖库䫘傖婋䂷悩
id | name | age | address | salary ----+-------+-----+-------------+-------- 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall | 45000 7 | James | 24 | Houston | 10000 8 | Paul | 24 | Houston | 20000 (7 rows)www.gitbook.net
傖婋滇婔婻冋床垄嚔滆䴺欔橬螄嘘傯噸埩臘䔇婄应儖橬婔婻誂庖严 - 麯麵䔇桺庖
www.gitbook.net
testdb=# SELECT * FROM COMPANY WHERE ADDRESS LIKE '%-%'; www.gitbook.net
認儖库䫘傖婋䂷悩 www.gitbook.net
id | name | age | address | salary ----+------+-----+-------------------------------------------+-------- 4 | Mark | 25 | Rich-Mond | 65000 6 | Kim | 22 | South-Hall | 45000 (2 rows) www.gitbook.net