sqlÖÐlikeÌåÏÖʲô
sql like ÔËËã·ûÓÃÓÚ¾ÙÐÐģʽƥÅ䣬Óï·¨ÊÇ select * from table_name where column_name like pattern; ģʽ¿ÉÒÔʹÓÃͨÅä·û %£¨í§Òâ×Ö·û£©ºÍ _£¨µ¥¸ö×Ö·û£©£¬Ö§³ÖתÒå×Ö·û¡¢×Ö·û¹æÄ£ºÍ not like ·ñ¶¨Æ¥Åä¡£µ«Òª×¢ÖØ like ÔËËã·ûÇø·Ö¾Þϸд£¬¹ØÓÚ´óÊý¾Ý±í¿ÉÄܽÏÂý¡£
SQL ÖÐ LIKE ÔËËã·û
LIKE ÔËËã·ûÓÃÓÚÔÚ SQL ÅÌÎÊÖоÙÐÐģʽƥÅä¡£Ëü¼ì²é×Ö·û´®ÊÇ·ñÓë¸ø¶¨µÄģʽƥÅä¡£
Óï·¨£º
SELECT * FROM table_name WHERE column_name LIKE pattern;
µÇ¼ºó¸´ÖÆ
ģʽ£º
ģʽ¿ÉÒÔ°üÀ¨ÒÔÏÂͨÅä·û£º
%£ºÆ¥Åäí§ÒâÊýÄ¿µÄ×Ö·û£¨°üÀ¨ 0 ¸ö×Ö·û£©¡£
_£ºÆ¥Åäµ¥¸ö×Ö·û¡£
ʾÀý£º
LIKE ‘dog%’£ºÆ¥ÅäÒÔ “dog” ¿ªÍ·µÄÈκÎ×Ö·û´®¡£
LIKE ‘%dog’£ºÆ¥ÅäÒÔ “dog” ×îºóµÄÈκÎ×Ö·û´®¡£
LIKE ‘%dog%’£ºÆ¥Åä°üÀ¨ “dog” µÄÈκÎ×Ö·û´®¡£
LIKE ‘d_g’£ºÆ¥Åä°üÀ¨ “d” ºÍ “g”£¬ÖÐÐÄÓÐÒ»¸öí§Òâ×Ö·ûµÄÈκÎ×Ö·û´®¡£
¸ß¼¶Ó÷¨£º
³ýÁËͨÅä·ûÖ®Í⣬LIKE ÔËËã·û»¹Ö§³ÖÆäËû¸ß¼¶Ó÷¨£º
תÒå×Ö·û£ºÔÚģʽÖÐʹÓ÷´Ð±¸Ü () תÒåÌØÊâ×Ö·û£¨Èç % ºÍ _£©¡£
×Ö·û¹æÄ££ºÊ¹Ó÷½À¨ºÅ ([ ]) ½ç˵×Ö·û¹æÄ£¡£ÀýÈ磬[a-z] Æ¥ÅäÈκÎСд×Öĸ¡£
·ñ¶¨£ºÊ¹Óà NOT LIKE ÔËËã·û²éÕÒ²»Æ¥Åä¸ø¶¨Ä£Ê½µÄ×Ö·û´®¡£
×¢ÖØÊÂÏ
LIKE ÔËËã·ûÇø·Ö¾Þϸд¡£
LIKE ÔËËã·û¹ØÓÚ°üÀ¨´ó×ÚÊý¾ÝµÄ±í¿ÉÄÜ»áºÜÂý¡£
ÔÚijЩÇéÐÎÏ£¬Ê¹Óà REGEXP ÔËËã·û¿ÉÄÜ±È LIKE ÔËËã·û¸üÓÐÓá£
ÒÔÉϾÍÊÇsqlÖÐlikeÌåÏÖʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡