比如有表Table1中一个字段
Field1
'abc<meta name="a" content="123/>def'
'abc<meta name="b" content="123/>def'
'abc<meta http-equiv="refresh" url=abc.com">def'
'sdfsdfd'
...如果Field1字段值中匹配有"<meta"字符串,且meta中有'url'字符串从字段值中删除如上所示,我要的结果是删除'abc<meta http-equiv="refresh" url=abc.com">def' 这条记录中的<meta http-equiv="refresh" url=abc.com">
Field1
'abc<meta name="a" content="123/>def'
'abc<meta name="b" content="123/>def'
'abc<meta http-equiv="refresh" url=abc.com">def'
'sdfsdfd'
...如果Field1字段值中匹配有"<meta"字符串,且meta中有'url'字符串从字段值中删除如上所示,我要的结果是删除'abc<meta http-equiv="refresh" url=abc.com">def' 这条记录中的<meta http-equiv="refresh" url=abc.com">
+------------------------------------------------+
| f |
+------------------------------------------------+
| abc<meta name="a" content="123/>def |
| abc<meta name="b" content="123/>def |
| abc<meta http-equiv="refresh" url=abc.com">def |
| sdfsdfd |
+------------------------------------------------+
4 rows in set (0.00 sec)mysql> update table1
-> set f=concat(mid(f,1,INSTR(f,'<meta')-1),mid(f,LOCATE('>',f,INSTR(f,'<meta'))+1))
-> where f like '%<meta%url%>%';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from table1;
+-------------------------------------+
| f |
+-------------------------------------+
| abc<meta name="a" content="123/>def |
| abc<meta name="b" content="123/>def |
| abcdef |
| sdfsdfd |
+-------------------------------------+
4 rows in set (0.00 sec)mysql>
set field1=concat(susbstring('field1','<',1),substring('field1','>',1))
where field1 like '%<meta%' and field1 like '%url%'
UPDATE table1
SET f=CONCAT(MID(f,1,INSTR(f,'<meta')-1),MID(f,LOCATE('>',f,INSTR(f,'<meta'))+1))
WHERE f LIKE '%<meta%url%>%';