SQLÖеÄREPLACEÌæ»»×Ö·ûº¯Êý
SQLÖеÄREPLACEÌæ»»×Ö·ûº¯ÊýµÄÓ÷¨£¨Ê¹Ö®Ö§³Ötext/ntext£©
Óï·¨
REPLACE ( original-string, search-string, replace-string )
²ÎÊý
Èç¹ûÓÐij¸ö²ÎÊýΪ NULL£¬´Ëº¯Êý·µ»Ø NULL¡£
original-string ±»ËÑË÷µÄ×Ö·û´®¡£¿ÉΪÈÎÒⳤ¶È¡£
search-string ÒªËÑË÷²¢±» replace-string Ìæ»»µÄ×Ö·û´®¡£¸Ã×Ö·û´®µÄ³¤¶È²»Ó¦³¬¹ý 255 ¸ö×Ö½Ú¡£Èç¹û search-string ÊÇ¿Õ×Ö·û´®£¬Ôò°´ÔÑù·µ»ØÔʼ×Ö·û´®¡£
replace-string ¸Ã×Ö·û´®ÓÃÓÚÌæ»» search-string¡£¿ÉΪÈÎÒⳤ¶È¡£Èç¹û replacement-string ÊÇ¿Õ×Ö·û´®£¬Ôòɾ³ý³öÏÖµÄËùÓÐ search-string¡£
Àý×Ó£º
UPDATE tableName SET recordName=REPLACE(recordName,'abc','ddd')
½«±ítableNameÖеÄrecordName×Ö¶ÎÖÐµÄ abc Ì滻Ϊ ddd
Õâ¸öº¯ÊýÓÐÒ»µã²»×ãÊDz»Ö§³Ö text,ntextÀàÐÍ×ֶεÄÌæ»»£¬¿ÉÒÔͨ¹ýÏÂÃæµÄÓï¾äÀ´ÊµÏÖ£º
update tableName set recordName=replace(cast(recordName as varchar(8000)) ,'abc','ddd')
ͨ¹ý cast º¯Êý°Ñtext×ֶεÄÄÚÈÝת»»ÎªvarcharÀàÐÍÔÙ½øÐÐÌæ»»
Ïà¹ØÎĵµ£º
2±êʶ·û¹æÔò
µ±Ê¹Óñêʶ·û¶¨Òå±äÁ¿ ³£Á¿Ê±£¬Ã¿ÐÐÖ»ÄܵÚÒ»Ò»¸ö±êʶ·û
µ±Ê¹Óñêʶ·û¶¨Òå±äÁ¿£¬³£Á¿Ê±£¬±êʶ·ûÃû³Æ±ØÐëÒªÒÔ°¢À²®×Ö·û£¨A~Z,a~z£©¿ªÊ¼£¬²¢ÇÒ×î´ó³¤¶ÈΪ30¸ö×Ö·û¡£Èç¹ûÒÔÆäËû×Ö·û¿ªÊ¼£¬ÄÇô±ØÐëҪʹÓÃË«ÒýºÅÒýס¡£
µ±Ê¹Óñêʶ·û¶¨Òå±äÁ¿³£Á¿Ê±£¬±êʶ·ûÃû³ÆÖ»ÄÜʹÓ÷ûºÅA~Z,a~z£¬0~9£¬_,$ºÍ#¡£Èç¹ûÊ¹Ó ......
master Êý¾Ý¿â
master Êý¾Ý¿â¼Ç¼ SQL Server ϵͳµÄËùÓÐϵͳ¼¶±ðÐÅÏ¢¡£Ëü¼Ç¼ËùÓеĵǼÕÊ»§ºÍϵͳÅäÖÃÉèÖá£master Êý¾Ý¿âÊÇÕâÑùÒ»¸öÊý¾Ý¿â£¬Ëü¼Ç¼ËùÓÐÆäËüµÄÊý¾Ý¿â£¬ÆäÖаüÀ¨Êý¾Ý¿âÎļþµÄλÖá£master Êý¾Ý¿â¼Ç¼ SQL Server µÄ³õʼ»¯ÐÅÏ¢£¬ËüʼÖÕÓÐÒ»¸ö¿ÉÓõÄ×îРmaster Êý¾Ý¿â±¸·Ý¡£ÓÉÓÚmasterÊý¾Ý¿â¶ÔSQL S ......
ÔÚÊý¾Ý¿â¿ª·¢¹ý³ÌÖУ¬µ±Äã¼ìË÷µÄÊý¾ÝÖ»ÊÇÒ»Ìõ¼Ç¼ʱ£¬ÄãËù±àдµÄÊÂÎñÓï¾ä´úÂëÍùÍùʹÓÃSELECT INSERT Óï¾ä¡£µ«ÊÇÎÒÃdz£³£»áÓöµ½ÕâÑùÇé¿ö£¬¼´´Óijһ½á¹û¼¯ÖÐÖðÒ»µØ¶ÁÈ¡Ò»Ìõ¼Ç¼¡£ÄÇôÈçºÎ½â¾öÕâÖÖÎÊÌâÄØ£¿ÓαêΪÎÒÃÇÌṩÁËÒ»ÖÖ¼«ÎªÓÅÐãµÄ½â¾ö·½°¸¡£
1.1 ÓαêºÍÓαêµÄÓŵã
ÔÚÊý¾Ý¿âÖУ¬ÓαêÊÇÒ»¸ö ......
×î½üѧSQL Server2005£¬ÏÂÔØÁËSQL2005ÖÐÎÄ¿ª·¢°æ£¬µ«ÊÇͬѧÃǶ¼°²×°ÉÏÁË£¬Î¨¶ÀÎҵĻúÆ÷°²×°²»ÉÏ¡£
ÿ´Î°²×°DATABASEµÄʱºò¶¼ÌáʾÎÞ·¨Æô¶¯sqlservr.exe·þÎñÎÞ·¨Æô¶¯£¬ÖØװϵͳҲ²»ÐУ¬WINXP WIN 7ÏÂÃ涼ÎÞ·¨°²×°£¬ÓÚÊÇÉÏÍø²éÁËÏ£¬ÔÀ´SQL2005²»Ö§³Ö3ºË´¦ÀíÆ÷£¬Î¢ÈíÒ²×Ô ......