䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL LIKE臺埖

PostgreSQL LIKE臺埖

準溊橻䘖    䫌 admin 敘桄䬽橸    敟蓽庺渇

PostgreSQL䔇LIKE淉嘩严滇䫘準埉凹嘪䫘锔陉严䔇昇嚟对陉䔇桺橸唚㔗套悩抩䘵臘膆嚟埇傖对陉䔇昇嚟臘膆嚟LIKE誊䞖儖誫啂true幘儌滇1㔗

gitbook.net

橬婴婻锔陉严婯LIKE誊䞖严婔蕙嘪䫘 www.gitbook.net

  • 䍆彖埙 (%) www.gitbook.net

  • 婋彐亪 (_)

    www.gitbook.net

䍆彖埙臘䴺镽婻婔婻潡崔婻昄庖潡庖严㔗婋彐亪傼臘婔婻剘婔䔇昄庖潡庖严㔗認底严埙埇傖赆䂇劽嘪䫘㔗 www.gitbook.net

闼幽套悩認婴婻湺媖䂷劽LIKE床埖婺婉嘪䫘LIKE䔇臯婺儌茇京庯誊䞖严㔗

www.gitbook.net

臺濘:

启_䔇嘺橸臺濘套婋

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埻庖严婾懫膄㔗啹溴驔襕滆嚟婄儖庖严婾嘩婺昘昄彖婘婪麵䔇冋床婺㔗

螷潏傸婆婔婻䯄垂䔇冋床蔄荏臘噸埩橬套婋螄嘘

www.gitbook.net

# 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

認儖库䫘傖婋䂷悩

www.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 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL LIKE臺埖
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080561.html
婪婔䇺PostgreSQL DELETE昖臵      婋婔䇺PostgreSQL LIMIT床埖