×ðÁú¿­Ê±¹ÙÍøµÇ¼

mysqlÖÐlikeÔõôÓÃ

like ÔËËã·ûÓÃÓÚ mysql ÖеÄģʽƥÅ䣬ËüʹÓÃͨÅä·ûÆ¥Åä×Ö·ûÐòÁУ¬°üÀ¨£º%£ºÆ¥ÅäÁã¸ö»ò¶à¸ö×Ö·û¡£_£ºÆ¥Åäµ¥¸ö×Ö·û¡£[ ]£ºÆ¥Åä·½À¨ºÅÄÚÁгöµÄÈκÎ×Ö·û¡£

MySQL ÖÐ LIKE ÔËËã·ûµÄʹÓÃ

LIKE ÔËËã·ûÓÃÓÚÔÚ MySQL ÖоÙÐÐģʽƥÅä¡£ËüÔÊÐíÄú²éÕÒÓëÌض¨Ä£Ê½Æ¥ÅäµÄÖµ£¬¸Ãģʽ¿ÉÒÔ°üÀ¨Í¨Åä·û¡£

ͨÅä·û£º

%£ºÆ¥ÅäÁã¸ö»ò¶à¸ö×Ö·û¡£

_£ºÆ¥Åäµ¥¸ö×Ö·û¡£

[list]£ºÆ¥Åä·½À¨ºÅÄÚÁгöµÄÈκÎ×Ö·û¡£

Óï·¨£º

SELECT column_name
FROM table_name
WHERE column_name LIKE 'pattern';

µÇ¼ºó¸´ÖÆ

ʾÀý£º

²éÕÒËùÓÐÒÔ “John” ¿ªÍ·µÄÃû×Ö£º

SELECT name
FROM customers
WHERE name LIKE 'John%';

µÇ¼ºó¸´ÖÆ

²éÕÒËùÓаüÀ¨×Öĸ “a” µÄÃû×Ö£º

SELECT name
FROM customers
WHERE name LIKE '%a%';

µÇ¼ºó¸´ÖÆ

²éÕÒËùÓÐÒÔ “John” ¿ªÍ·ÇÒÒÔ “son” ×îºóµÄÃû×Ö£º

SELECT name
FROM customers
WHERE name LIKE 'John%son';

µÇ¼ºó¸´ÖÆ

ÌáÐÑ£º

ͨÅä·û % ºÍ _ ¿ÉÒÔÔÚģʽÖеÄÈκÎλÖÃʹÓá£

¿ÉÒÔʹÓ÷½À¨ºÅ [ ] ½¨Éè×Ö·û¹æÄ£¡£ÀýÈ磬'[a-z]’ Æ¥ÅäÈκÎСд×Öĸ¡£

LIKE ÔËËã·ûÇø·Ö¾Þϸд£¬³ý·ÇʹÓà BINARY Òªº¦×Ö¡£ÀýÈ磬’John%’ Æ¥Åä “John”£¬µ« ‘john%’ ²»Æ¥Åä¡£

ÈôÊÇģʽÖаüÀ¨Í¨Åä·û£¬ÔòÓ¦½«Í¨Åä·ûתÒ壬ÒÔÃâËüÃDZ»Ú¹ÊÍΪÎı¾¡£ÀýÈ磬’\%’ Æ¥Åä “%” ×Ô¼º¡£

ÒÔÉϾÍÊÇmysqlÖÐlikeÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ