SQL ͨÅä·û
SQL ͨÅä·û
ÔÚËÑË÷Êý¾Ý¿âÖеÄÊý¾Ýʱ£¬Äú¿ÉÒÔʹÓà SQL ͨÅä·û¡£
SQL ͨÅä·û
ÔÚËÑË÷Êý¾Ý¿âÖеÄÊý¾Ýʱ£¬SQL ͨÅä·û¿ÉÒÔÌæ´úÒ»¸ö»ò¶à¸ö×Ö·û¡£
SQL ͨÅä·û±ØÐëÓë LIKE ÔËËã·ûÒ»ÆðʹÓá£
ÔÚ SQL ÖУ¬¿ÉʹÓÃÒÔÏÂͨÅä·û£º
ͨÅä·ûÃèÊö
%
Ìæ´úÒ»¸ö»ò¶à¸ö×Ö·û
_
½öÌæ´úÒ»¸ö×Ö·û
[charlist]
×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
[^charlist]
»òÕß
[!charlist]
²»ÔÚ×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
ÔʼµÄ±í (ÓÃÔÚÀý×ÓÖеÄ)£º
Persons ±í:
IdLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
2
Bush
George
Fifth Avenue
New York
3
Carter
Thomas
Changan Street
Beijing
ʹÓà % ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚÒÔ "Ne" ¿ªÊ¼µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE 'Ne%'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
2
Bush
George
Fifth Avenue
New York
Àý×Ó 2
½ÓÏÂÀ´£¬ÎÒÃÇÏ£Íû´Ó "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚ°üº¬ "lond" µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE '%lond%'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
ʹÓà _ ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡Ãû×ֵĵÚÒ»¸ö×Ö·ûÖ®ºóÊÇ "eorge" µÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE FirstName LIKE '_eorge'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
2
Bush
George
Fifth Avenue
New York
Àý×Ó 2
½ÓÏÂÀ´£¬ÎÒÃÇÏ£Íû´Ó "Persons" ±íÖÐÑ¡È¡µÄÕâÌõ¼Ç¼µÄÐÕÊÏÒÔ "C" ¿ªÍ·£¬È»ºóÊÇÒ»¸öÈÎÒâ×Ö·û£¬È»ºóÊÇ "r"£¬È»ºóÊÇÈÎÒâ×Ö·û£¬È»ºóÊÇ "er"£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE LastName LIKE 'C_r_er'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
3
Carter
Thomas
Changan Street
Beijing
ʹÓà [charlist] ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסµÄ³ÇÊÐÒÔ "A" »ò "L" »ò "N" ¿ªÍ·µÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE '[ALN]%'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
2
Bush
George
Fifth Avenue
New York
Àý×Ó 2
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "P
Ïà¹ØÎĵµ£º
ÉÏÍøÒ»²é£¬SQL server2008¶¼³öÀ´ÁË£¬ÎÒ»¹ÊÇÏÈ´Ó»ù´¡µÄѧÆð°É¡£
SQL server2000µÄ³£¼û°æ±¾ÓУºÆóÒµ°æ¡¢±ê×¼°æ¡¢¸öÈË°æ¡¢¿ª·¢°æ¡£
ÆóÒµ°æ£º¹¦ÄÜÈ«Ã棬ӦÓÃÓÚ´óÖÐÐͲúÆ··þÎñ´¦ÀíÆ÷£¬Ö§³Ö´óÐÍÍøÕ¾¡¢Áª»úÊÂÎñ´¦Àí£¬Áª»ú·ÖÎö´¦ÀíµÄÐÔÄÜ¡£
±ê×¼°æ£ºÊÊÓÃÓÚСÐ͹¤×÷×飬²»Ö§³Ö´óÐÍÊý¾Ý¿â£¬Êý¾Ý²Ö¿âºÍÍøÕ¾µÄ¹¦ÄÜ£¬¶øÇÒ²»Ö§³ÖËùÓÐ¹Ø ......
¶ÔÏóÃüÃûµÄÔ¼¶¨£ºÊý¾Ý¿âÃû.ËùÓÐÕßÃû.¶ÔÏóÃû
Ç°Á½Õß¿ÉÊ¡ÂÔ£¬Ä¬ÈÏÖµÊý¾Ý¿âÊǵ±Ç°Êý¾Ý¿â£¬ËùÓÐÕßÊÇdbo
±ðÃû£ºÊý¾Ý¿âÃû³Æ as Êý¾Ý¿â±íÃû Ö÷ÒªÊÇÔö¼ÓselectÓï¾äµÄ¿É¶ÁÐÔ£¬Èç¹ûÒѾΪÊý¾Ý±íÖƶ¨Á˱ðÃû£¬Ôò
ÔÚÏàÓ¦µÄSQLÓï¾äÖУ¬¶Ô¸ÃÊý¾Ý±íµÄËùÓÐÏÔʾÒýÓö¼ÒªÊ¹ÓñðÃû£¬¶ø²»ÄÜʹÓÃÊý¾Ý±íÃû¡£
selectÓï¾äÊÇÊý¾Ý¼ìË÷ÖÐ×îƵ·±µÄ»î¶ ......
from×Ó¾äÖ¸¶¨ÐèÒª½øÐÐÊý¾Ý²éѯµÄ±í£¬ÊÓͼµÈÊý¾ÝÔ´£¬ÓöººÅ·Ö¸ô¡£
from×Ӿ仹¿ÉÒÔÖ¸¶¨Êý¾Ý±í»òÊÓͼ֮¼äµÄÁ¬½ÓÀàÐÍ£¬ÀàÐÍÈ¡¾öÓÚon×Ó¾äÖÐÖ¸¶¨µÄÁ¬½ÓÌõ¼þ¡£
T-SQL¿ÉÒÔÖ§³ÖÔÚfrom×Ó¾äÖÐÖ¸¶¨³ýÊý¾Ý±í»òÊÓͼÍâµÄÆäËû¶ÔÏó¹¹³ÉÅÉÉú±í¡£
ÀýÈ磺select emp.Ô±¹¤±àºÅ£¬emp.Ô±¹¤ÐÕÃû£¬sp.²¿ÃÅÃû³Æ
fr ......
exec('selectIDENTITY(int,1,1) as ID,fnum,into #yuecu from store_store where '+@Parameter)
select XX,XX1,XX2 from #yuecu
ÕâÑù´´½¨Ò»¸öÁÙʱ±íÒÔºóÎÒÔÙÏë´ÓÁÙʱ±íÖÐÈ¡Êý¾ÝÌáʾ¶ÔÏóÃû#yuecu&n ......
Oracle SQL Developer ÊÇÒ»¸öÃâ·ÑµÄͼÐλ¯Êý¾Ý¿â¿ª·¢¹¤¾ß¡£Ê¹Óà SQL Developer£¬Äú¿ÉÒÔä¯ÀÀÊý¾Ý¿â¶ÔÏó¡¢ÔËÐÐ SQL Óï¾äºÍ SQL ½Å±¾£¬²¢ÇÒ»¹¿ÉÒԱ༺͵÷ÊÔ PL/SQL Óï¾ä¡£Äú»¹¿ÉÒÔÔËÐÐËùÌṩµÄÈκÎÊýÁ¿µÄ±¨±í£¬ÒÔ¼°´´½¨ºÍ±£´æÄú×Ô¼ºµÄ±¨±í¡£SQL Developer ¿ÉÒÔÌá¸ß¹¤×÷ЧÂʲ¢¼ò»¯Êý¾Ý¿â¿ª·¢ÈÎÎñ¡£
SQL Developer ¿ÉÒÔÁ¬½Óµ½È ......