我有一个MySQL字段,其中包含如下字符串,我需要替换其中的一部分而不影响其他部分。
“http://mydomain.com/app/web/index.php/reqyest/RequestForm/id/661,#SDATERANGE#from#DATE#2015-03-23#DATERANGE#to#DATE#2015-03 -26#DATERANGE ## DATECLAIMID#1100#DATECLAIMID ## SDATERANGE#,#TIMERANGE#FROMTIME-11:00#TIME#TOTIME-23:00#TIME ## TIMECLAIMID#1100#TIMECLAIMID ## TIMERANGE#,84.0 / 0.00 / 732.9 /海外//,@ 1100%22%@#17#出租车费用和豪华轿车:123.49:jkta trip-ppit agm taxi.pdf:1100;“
“http://mydomain.com/reqyest/RequestForm/id/661,#SDATERANGE#from#DATE#2015-03-23#DATERANGE#to#DATE#2015-03-26#DATERANGE##DATECLAIMID# 1100#DATECLAIMID ## SDATERANGE#,##TIMERANGE放在fromtime,11:00#TIME#TOTIME-23:00#时间## TIMECLAIMID#1100#TIMECLAIMID ## TIMERANGE#,84.0 / 0.00 / 732.9 /海外// @ 1100 %22%@#17#出租车费用和豪华轿车:123.49:jkta trip-ppit agm taxi.pdf:1100;“
以下是我正在使用的查询。
update table_name set table_name.field = replace (field,"/app\/web\/index.php\/","/");
我尝试了下面提供的建议而没有成功。
答案 0 :(得分:0)
你需要逃避' /'用' \'让mysql知道它是该字段的一个字符,而不是一个特殊的字符。 试试这个:
update table_name set table_name.field = replace(field,"\/app\/web\/index.php\/","\/")
答案 1 :(得分:0)
我得到了以下结果,这正如您所期望的那样。 “/”不是转义字符,因此不需要特殊处理。
mysql> SELECT REPLACE ( "http://example.com/app/web/index.php/reqyest/RequestForm/id/661,#SDATERANGE#from#DATE#2015-03-23#DATERANGE#to#DATE#2015-03-26#DATERANGE##DATECLAIMID#1100#DATECLAIMID##SDATERANGE#,#TIMERANGE#fromtime-11:00#TIME#totime-23:00#TIME##TIMECLAIMID#1100#TIMECLAIMID##TIMERANGE#,84.0/0.00/732.9/Overseas//,@1100%22%@#17#Taxi fare & Limousine:123.49:jkta trip-ppit agm taxi.pdf:1100;",
-> "/app/web/index.php/","/");
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| REPLACE ( "http://example.com/app/web/index.php/reqyest/RequestForm/id/661,#SDATERANGE#from#DATE#2015-03-23#DATERANGE#to#DATE#2015-03-26#DATERANGE##DATECLAIMID#1100#DATECLAIMID##SDATERANGE#,#TIMERANGE#fromtime-11:00#TIME#totime-23:00#TIME##TIMECLAIMID#110 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| http://example.com/reqyest/RequestForm/id/661,#SDATERANGE#from#DATE#2015-03-23#DATERANGE#to#DATE#2015-03-26#DATERANGE##DATECLAIMID#1100#DATECLAIMID##SDATERANGE#,#TIMERANGE#fromtime-11:00#TIME#totime-23:00#TIME##TIMECLAIMID#1100#TIMECLAIMID##TIMERANGE#,84.0/0.00/732.9/Overseas//,@1100%22%@#17#Taxi fare & Limousine:123.49:jkta trip-ppit agm taxi.pdf:1100; |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)