SQL LIKE ͨÅä·û
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 ±È½Ï¡£Á˽âÿÖÖÊý¾ÝÀàÐ͵Ĵ洢·½Ê½ÒÔ¼°µ¼ÖÂ
Ïà¹ØÎĵµ£º
ÔÚжÔØVisual Studio 2008 ʱ£¬Ìí¼Ó/ɾ³ý³ÌÐò ÀïÃæÓÐÐí¶àµÄ°²×°Îļþ£¬´ËʱÈç¹ûûÓÐÏÈжÔØSQL Server 2005 £¬
¶øÏÈжÔØ.Net Framework£¨Ìáʾ£ºÐ¶ÔØ.net FrameworkµÄµÃ°²°æ±¾´Ó¸ßµ½µÍµÄ˳Ðò£©£¬
ÕâʱSQL Server 2005¾ÍÎÞ·¨Ð¶ÔØ,ɾ³ýProgram files ÏÂÃæµÄ Microsoft SQL Server Îļþ¼ÐҲûÓÐ×÷Óá£
ÖØа²×°ÌáʾÊý¾Ý¿ ......
SQLÖеÄREPLACEÌæ»»×Ö·ûº¯ÊýµÄÓ÷¨£¨Ê¹Ö®Ö§³Ötext/ntext£©
Óï·¨
REPLACE ( original-string, search-string, replace-string )
²ÎÊý
Èç¹ûÓÐij¸ö²ÎÊýΪ NULL£¬´Ëº¯Êý·µ»Ø NULL¡£
original-string ±»ËÑË÷µÄ×Ö·û´®¡£¿ÉΪÈÎÒⳤ¶È¡£
search-string ÒªËÑË÷²¢±» repl ......
1. >>¼ÓÃÜ
from the Books Online:
Use the WITH ENCRYPTION option:
IF EXISTS (SELECT name from sysobjects
WHERE name = 'encrypt_this' AND type = 'P')
DROP PROCEDURE encrypt_this
GO
USE pubs
GO
CREATE PROCEDURE encrypt_this
WITH ENCRYPTION
AS
SELECT *
from authors
GO
EXEC sp ......
GROUP BY ×Ó¾äÓÃÀ´¶ÔÖ¸¶¨µÄ×Ö¶Î×ö·Ö×飬²úÉúÒ»¸ö»ã×ÜÐÅÏ¢¡£ £¨1£©group byÓï¾ä¶ÔselectºóËùÑ¡ÔñµÄ×Ö¶ÎÓÐÒ»¶¨µÄÏÞÖÆ£¬¼´selectºóûÓÐʹÓþۺϺ¯ÊýµÄ×ֶαØÐë°üº¬ÔÚgroup by Óï¾äºóÃæµÄ½á¹û¼¯ÖС££¨GROUP BY ¹Ø¼ü×Öºó¸úÒ»¸öÁеÄÁÐ±í£¬³ÆΪ×éºÏÁУ©. £¨2£©²»ÄܶÔÊý¾ÝÀàÐÍΪ ntext¡¢text¡¢image »ò bit µÄÁÐʹÓà GROUP BY »ò ......