[SQL] patindex Ïê½â
PATINDEX
·µ»ØÖ¸¶¨±í´ïʽÖÐijģʽµÚÒ»´Î³öÏÖµÄÆðʼλÖã»Èç¹ûÔÚÈ«²¿ÓÐЧµÄÎı¾ºÍ×Ö·ûÊý¾ÝÀàÐÍÖÐûÓÐÕÒµ½¸Ãģʽ£¬Ôò·µ»ØÁã¡£
Óï·¨
PATINDEX ( '%pattern%' , expression )
²ÎÊý
pattern
Ò»¸ö×Ö·û´®¡£¿ÉÒÔʹÓÃͨÅä·û£¬µ« pattern ֮ǰºÍÖ®ºó±ØÐëÓÐ % ×Ö·û£¨ËÑË÷µÚÒ»¸öºÍ×îºóÒ»¸ö×Ö·ûʱ³ýÍ⣩¡£pattern ÊǶÌ×Ö·ûÊý¾ÝÀàÐÍÀà±ðµÄ±í´ïʽ¡£
expression
Ò»¸ö±í´ïʽ£¬Í¨³£ÎªÒªÔÚÆäÖÐËÑË÷Ö¸¶¨Ä£Ê½µÄÁУ¬expression Ϊ×Ö·û´®Êý¾ÝÀàÐÍÀà±ð¡£
·µ»ØÀàÐÍ
int
×¢ÊÍ
PATINDEX ¶Ô text Êý¾ÝÀàÐͺÜÓÐÓ㻳ý IS NULL¡¢IS NOT NULL ºÍ LIKE£¨ÕâЩÊÇ Where ×Ó¾äÖÐ¶Ô text ÀàÐÍÓÐЧµÄ½öÓеÄÆäËü±È½ÏÔËË㣩Í⣬PATINDEX Ò²¿ÉÓÃÓÚ Where ×Ó¾äÖС£
£££££££££££££££££££££££££££££££££££££££££
ÀýÒ»:
ÕÒ³öNorthwind.dbo.Categories±íÖÐDescription×Ö¶ÎÖÐÊÇ°üº¬µ¥´Ê“Bread”»ò“bread”µÄËùÓмǼ£¬ÄÇôѡÔñÓï¾ä¾Í¿ÉÄÜÊÇÕâÑù£º
Select Description from Northwind.dbo.Categories
Where patindex('%[b,B]read%',description) > 0
PATINDEX ÖпÉÒÔʹÓÃͨÅä·ûÀ´È·¶¨´óдºÍСдµÄ“b”
Àý¶þ:
ÕÒ³öNorthwind.dbo.Categories±íÖÐDescription×Ö¶ÎÖÐÊÇ°üº¬µ¥´Ê“Bread”»ò“bread”,ÇÒµÚ¶þ×Ó×Öĸ²»ÊÇ“e”µÄ¼Ç¼¡£
select Description from Northwind.dbo.Categories
where patindex('%[b,B]read%',description) > 0 and patindex('_[^e]%',description) = 1
ͨ¹ýÔÚÌõ¼þÓï¾äÖÐÔö¼ÓÒ»¸öʹÓÃ^ͨÅä·ûµÄPATINDEXº¯Êý£¬ÎÒÃÇ¿ÉÒÔ¹ýÂ˵ô“Dessert, candies, and sweet breads”ÕâÌõ¼Ç¼¡£ÉÏÃæµÄ²éѯ½á¹ûÖ»ÓÐÒ»Ìõ¼Ç¼¡£
PATINDEXÓëCHARINDEX
PATINDEXº¯ÊýÖ§³ÖʹÓÃͨÅä·û£¬¿ÉÒÔÓÃÔںܶàÓб仯µÄ²éÕÒÖС£¶øCHARINDEX²»¿ÉÒÔ¡£¸ù¾ÝÄã×Ô¼º²»Í¬µÄÇé¿ö£¬ÕâÁ½¸öº¯Êý¶ÔÄãÔÚSQL ServerÖеÄ×Ö·û´®µÄËÑË÷¡¢¿ØÖÆ¡¢·ÖÎöºÜÓаïÖú¡£
Ïà¹ØÎĵµ£º
ORACLE SQLÐÔÄÜÓÅ»¯
ORACLE SQLÐÔÄÜÓÅ»¯ÏµÁÐ (Ò»)
1. Ñ¡ÓÃÊʺϵÄORACLEÓÅ»¯Æ÷
ORACLEµÄÓÅ»¯Æ÷¹²ÓÐ3ÖÖ:
a. RULE (»ùÓÚ¹æÔò) b. COST (»ùÓڳɱ¾) c. CHOOSE (Ñ¡ÔñÐÔ)
ÉèÖÃȱʡµÄÓÅ»¯Æ÷,¿ÉÒÔͨ¹ý¶Ôinit.oraÎļþÖÐOPTIMIZER_MODE²ÎÊýµÄ¸÷ÖÖÉùÃ÷,ÈçRULE,COST,CHOOSE,ALL_ROWS,FIRST_ROWS . Ä㵱ȻҲÔÚSQ ......
µ±ÔÚÄÚÁ¬½Ó²éѯÖмÓÈëÌõ¼þʱ£¬ÎÞÂÛÊǽ«Ëü¼ÓÈëµ½join×Ӿ䣬»¹ÊǼÓÈëµ½where×Ӿ䣬ÆäЧ¹ûÊÇÍêÈ«Ò»ÑùµÄ£¬µ«¶ÔÓÚÍâÁ¬½ÓÇé¿ö¾Í²»Í¬ÁË¡£µ±°ÑÌõ¼þ¼ÓÈëµ½ join×Ó¾äʱ£¬»á·µ»ØÍâÁ¬½Ó±íµÄÈ«²¿ÐУ¬È»ºóʹÓÃÖ¸¶¨µÄÌõ¼þ·µ»ØµÚ¶þ¸ö±íµÄÐС£Èç¹û½«Ìõ¼þ·Åµ½where×Ó¾äÖУ¬½«»áÊ×ÏȽøÐÐÁ¬½Ó²Ù×÷£¬È»ºóʹÓÃwhere×Ó¾ä¶ÔÁ¬½ÓºóµÄÐнøÐÐɸѡ¡ ......
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname ......
´ÓÍøÂçÉÏ¿´µ½²»ÉÙ¹ØÓÚÊý¾Ý¿âÔ¶³Ì·ÃÎÊÅäÖõÄÎÄÕ£¬¸øÎҵĴóÌåÓ¡Ïó¾ÍÊÇÅäÖùý³Ì¸´ÔÓÈßÓ࣬Óв»ÉÙ»¹ÊÇ´íÎóµÄÅäÖÆ·½·¨£¬´ó¶àÊý¶¼ÈÃÈ˸оõ·Ñ½â£¬¼øÓÚ´Ë£¬ÎÒ×Ô¼º¸ù¾Ýʵ¼Ê²Ù×÷£¬Ð´ÁËÒ»¸öÊý¾Ý¿âÔ¶³Ì·ÃÎʵÄÅäÖ÷½·¨£¬Á¦Çó¼òµ¥ÓÐЧ¡£ÓжÔÏÂÃæÅäÖÃÓÐÒÉÎʵĿÉÒÔÁôÑÔ£¬ÎÒ½«×÷³ö»Ø´ð¡£
1. &nb ......
MYSQLÊý¾Ý¿âÖеij£ÓÃSQLÓï¾ä
1¡¢SELECT ²éѯÓï¾äºÍÌõ¼þÓï¾ä
SELECT ²éѯ×ֶΠfrom ±íÃû WHERE Ìõ¼þ
²éѯ×ֶΣº¿ÉÒÔʹÓÃͨÅä·û* ¡¢×Ö¶ÎÃû¡¢×ֶαðÃû
±íÃû£º Êý¾Ý¿â.±íÃû £¬±íÃû
³£ÓÃÌõ¼þ£º = µÈÓÚ ¡¢<>²»µÈÓÚ¡¢in °üº¬ ¡¢&nb ......