SQLÄ£ºý²éѯÓï¾ä(like)
È·¶¨¸ø¶¨µÄ×Ö·û´®ÊÇ·ñÓëÖ¸¶¨µÄģʽƥÅ䡣ģʽ¿ÉÒÔ°üº¬³£¹æ×Ö·ûºÍͨÅä·û×Ö·û¡£Ä£Ê½Æ¥Åä¹ý³ÌÖУ¬³£¹æ×Ö·û±ØÐëÓë×Ö·û´®ÖÐÖ¸¶¨µÄ×Ö·ûÍêÈ«Æ¥Å䡣Ȼ¶ø£¬¿É ʹÓÃ×Ö·û´®µÄÈÎÒâƬ¶ÎÆ¥ÅäͨÅä·û¡£ÓëʹÓà = ºÍ != ×Ö·û´®±È½ÏÔËËã·ûÏà±È£¬Ê¹ÓÃͨÅä·û¿Éʹ LIKE ÔËËã·û¸ü¼ÓÁé»î¡£Èç¹ûÈκβÎÊý¶¼²»ÊôÓÚ×Ö·û´®Êý¾ÝÀàÐÍ£¬Microsoft SQL Server »á½«Æäת»»³É×Ö·û´®Êý¾ÝÀàÐÍ£¨Èç¹û¿ÉÄÜ£©¡£
Óï·¨
match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ]
²ÎÊý
match_expression
ÈκÎ×Ö·û´®Êý¾ÝÀàÐ͵ÄÓÐЧ SQL Server ±í´ïʽ¡£
pattern
match_expression ÖеÄËÑË÷ģʽ£¬¿ÉÒÔ°üº¬ÏÂÁÐÓÐЧ SQL Server ͨÅä·û¡£
ͨÅä·ûÃèÊöʾÀý
%
°üº¬Áã¸ö»ò¸ü¶à×Ö·ûµÄÈÎÒâ×Ö·û´®¡£
WHERE title LIKE '%computer%' ½«²éÕÒ´¦ÓÚÊéÃûÈÎÒâλÖõİüº¬µ¥´Ê computer µÄËùÓÐÊéÃû¡£
_£¨Ï»®Ïߣ©
Èκε¥¸ö×Ö·û¡£
WHERE au_fname LIKE '_ean' ½«²éÕÒÒÔ ean ½áβµÄËùÓÐ 4 ¸ö×ÖĸµÄÃû×Ö£¨Dean¡¢Sean µÈ£©¡£
[ ]
Ö¸¶¨·¶Î§ ([a-f]) »ò¼¯ºÏ ([abcdef]) ÖеÄÈκε¥¸ö×Ö·û¡£
WHERE au_lname LIKE '[C-P]arsen' ½«²éÕÒÒÔarsen ½áβÇÒÒÔ½éÓÚ C Óë P Ö®¼äµÄÈκε¥¸ö×Ö·û¿ªÊ¼µÄ×÷ÕßÐÕÊÏ£¬ÀýÈ磬Carsen¡¢Larsen¡¢Karsen µÈ¡£
[^]
²»ÊôÓÚÖ¸¶¨·¶Î§ ([a-f]) »ò¼¯ºÏ ([abcdef]) µÄÈκε¥¸ö×Ö·û¡£
WHERE au_lname LIKE 'de[^l]%' ½«²éÕÒÒÔ de ¿ªÊ¼ÇÒÆäºóµÄ×Öĸ²»Îª l µÄËùÓÐ×÷ÕßµÄÐÕÊÏ¡£
escape_character
×Ö·û´®Êý¾ÝÀàÐÍ·ÖÀàÖеÄËùÓÐÊý¾ÝÀàÐ͵ÄÈκÎÓÐЧ SQL Server ±í´ïʽ¡£escape_character ûÓÐĬÈÏÖµ£¬ÇÒ±ØÐë½ö°üº¬Ò»¸ö×Ö·û¡£
½á¹ûÀàÐÍ
Boolean
½á¹ûÖµ
Èç¹û match_expression Æ¥ÅäÖ¸¶¨Ä£Ê½£¬LIKE ½«·µ»Ø TRUE¡£
×¢ÊÍ
µ±Ê¹Óà LIKE ½øÐÐ×Ö·û´®±È½Ïʱ£¬Ä£Ê½×Ö·û´®ÖеÄËùÓÐ×Ö·û¶¼ÓÐÒâÒ壬°üÀ¨Æðʼ»òβËæ¿Õ¸ñ¡£Èç¹û²éѯÖеıȽÏÒª·µ»Ø°üº¬"abc "£¨abc ºóÓÐÒ»¸ö¿Õ¸ñ£©µÄËùÓÐÐУ¬Ôò½«²»»á·µ»Ø°üº¬"abc"£¨abc ºóûÓпոñ£©µÄÁÐËùÔÚÐС£µ«ÊÇ¿ÉÒÔºöÂÔģʽËùҪƥÅäµÄ±í´ïʽÖеÄβËæ¿Õ¸ñ¡£Èç¹û²éѯÖеıȽÏÒª·µ»Ø°üº¬"abc"£¨abc ºóûÓпոñ£©µÄËùÓÐÐУ¬Ôò½«·µ»ØÒÔ"abc"¿ªÊ¼ÇÒ¾ßÓÐÁã¸ö»ò¶à¸öβËæ¿Õ¸ñµÄËùÓÐÐС£
ÓÉÓÚÊý¾Ý´æ´¢·½Ê½µÄÔÒò£¬Ê¹Óðüº¬ char ºÍ varchar Êý¾ÝģʽµÄ×Ö·û´®±È½Ï¿ÉÄÜÎÞ·¨Í¨¹ý LIKE ±È½Ï¡£Á˽âÿÖÖÊý¾ÝÀàÐ͵Ĵ洢·½Ê½ÒÔ¼°µ¼Ö LIKE ±È½Ïʧ°ÜµÄÔÒòÊ®·ÖÖØÒª¡£ÏÂÃæµÄʾÀý½«¾Ö²¿ char ±äÁ¿´«µÝ¸ø´æ´¢¹ý³Ì£¬È»ºóʹÓÃģʽƥÅä²éÕÒij¸ö×÷ÕßµÄËùÓÐÖø×÷¡£Ôڴ˹ý³ÌÖУ
Ïà¹ØÎĵµ£º
Èç¹ûÄã¾³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLÏ°¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......
£¨×ªÔØ£©SQL 2K Êý¾ÝÀàÐÍ
(1)char¡¢varchar¡¢textºÍnchar¡¢nvarchar¡¢ntext
charºÍvarcharµÄ³¤¶È¶¼ÔÚ1µ½8000Ö®¼ä£¬ËüÃǵÄÇø±ðÔÚÓÚcharÊǶ¨³¤×Ö·ûÊý¾Ý£¬¶øvarcharÊDZ䳤×Ö·ûÊý¾Ý¡£Ëùν¶¨³¤¾ÍÊdz¤¶È¹Ì¶¨µÄ£¬µ±ÊäÈëµÄÊý¾Ý³¤¶ÈûÓдﵽָ¶¨µÄ³¤¶Èʱ½«×Ô¶¯ÒÔÓ¢ÎÄ¿Õ¸ñÔÚÆäºóÃæÌî³ä£¬Ê¹³¤¶È´ïµ½ÏàÓ¦µÄ³¤¶È£»¶ø±ä³¤×Ö·ûÊý¾Ý ......
´æ´¢¹ý³Ì´úÂ룺
--drop procedure p_page
--go
create procedure p_page
(
@Tables varchar(1000), --±íÃûÈçtesttable
@PrimaryKey varchar(100),--±íµÄÖ÷¼ü,±ØÐëΨһÐÔ
@Sort varchar(200) = NULL,--ÅÅÐò×Ö¶ÎÈçf_Name asc»òf_name desc(×¢ÒâÖ»ÄÜÓÐÒ»¸öÅÅÐò×Ö¶Î)
@CurrentPage int = 1,--µ± ......