你一定会喜欢这个的
首先,这里是一个加载了数据的示例表:
mysql> use junk
Database changed
mysql> drop table todd;
Query OK, 0 rows affected (0.01 sec)
mysql> create table todd (id int not null auto_increment,url VARCHAR(255),
-> primary key (id)) ENGINE=MyISAM;
Query OK, 0 rows affected (0.05 sec)
mysql> INSERT INTO todd (url) VALUES
-> (\'<img height=319 alt="" src="http://www.example.com/images/myexample.jpg" width=496>\'),
-> (\'<img height=329 alt="" src="http://www.example.com/images/myexample.jpg" width=130>\'),
-> (\'<img height=339 alt="" src="http://www.example.com/images/myexample.jpg" width=206>\'),
-> (\'<img height=349 alt="" src="http://www.example.com/images/myexample.jpg" width=498>\'),
-> (\'<img height=359 alt="" src="http://www.example.com/images/myexample.jpg" width=499>\');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from todd;
+----+-------------------------------------------------------------------------------------+
| id | url |
+----+-------------------------------------------------------------------------------------+
| 1 | <img height=319 alt="" src="http://www.example.com/images/myexample.jpg" width=496> |
| 2 | <img height=329 alt="" src="http://www.example.com/images/myexample.jpg" width=130> |
| 3 | <img height=339 alt="" src="http://www.example.com/images/myexample.jpg" width=206> |
| 4 | <img height=349 alt="" src="http://www.example.com/images/myexample.jpg" width=498> |
| 5 | <img height=359 alt="" src="http://www.example.com/images/myexample.jpg" width=499> |
+----+-------------------------------------------------------------------------------------+
5 rows in set (0.00 sec)
mysql>
必须依次运行两个查询:
这个在数字的高度加上双引号
UPDATE
(select id,CONCAT(bftoken,token,\'"\',num,\'"\',substr(aftoken,num_length+1)) newurl
FROM (select id,token,
substr(b.url,1,a.hpos - 1) bftoken,
substr(b.url,a.hpos + length(a.token)) aftoken,
substr(b.url,a.hpos + length(a.token))+0 num,
length(substr(b.url,a.hpos + length(a.token))+0) num_length
from
(select id,token,LOCATE(token,url) hpos
from todd,(select \'height=\' token) w
WHERE LOCATE(CONCAT(token,\'"\'),url)=0) A
INNER JOIN todd B USING (id)) AA) AAA
INNER JOIN todd BBB USING (id)
SET BBB.url = AAA.newurl;
这个在数字宽度周围加上双引号
UPDATE
(select id,CONCAT(bftoken,token,\'"\',num,\'"\',substr(aftoken,num_length+1)) newurl
FROM (select id,token,
substr(b.url,1,a.hpos - 1) bftoken,
substr(b.url,a.hpos + length(a.token)) aftoken,
substr(b.url,a.hpos + length(a.token))+0 num,
length(substr(b.url,a.hpos + length(a.token))+0) num_length
from
(select id,token,LOCATE(token,url) hpos
from todd,(select \'width=\' token) w
WHERE LOCATE(CONCAT(token,\'"\'),url)=0) A
INNER JOIN todd B USING (id)) AA) AAA
INNER JOIN todd BBB USING (id)
SET BBB.url = AAA.newurl;
观察我运行这些并显示表内容时发生的情况:
mysql> UPDATE
-> (select id,CONCAT(bftoken,token,\'"\',num,\'"\',substr(aftoken,num_length+1)) newurl
-> FROM (select id,token,
-> substr(b.url,1,a.hpos - 1) bftoken,
-> substr(b.url,a.hpos + length(a.token)) aftoken,
-> substr(b.url,a.hpos + length(a.token))+0 num,
-> length(substr(b.url,a.hpos + length(a.token))+0) num_length
-> from
-> (select id,token,LOCATE(token,url) hpos
-> from todd,(select \'height=\' token) w
-> WHERE LOCATE(CONCAT(token,\'"\'),url)=0) A
-> INNER JOIN todd B USING (id)) AA) AAA
-> INNER JOIN todd BBB USING (id)
-> SET BBB.url = AAA.newurl;
Query OK, 5 rows affected (0.02 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> UPDATE
-> (select id,CONCAT(bftoken,token,\'"\',num,\'"\',substr(aftoken,num_length+1)) newurl
-> FROM (select id,token,
-> substr(b.url,1,a.hpos - 1) bftoken,
-> substr(b.url,a.hpos + length(a.token)) aftoken,
-> substr(b.url,a.hpos + length(a.token))+0 num,
-> length(substr(b.url,a.hpos + length(a.token))+0) num_length
-> from
-> (select id,token,LOCATE(token,url) hpos
-> from todd,(select \'width=\' token) w
-> WHERE LOCATE(CONCAT(token,\'"\'),url)=0) A
-> INNER JOIN todd B USING (id)) AA) AAA
-> INNER JOIN todd BBB USING (id)
-> SET BBB.url = AAA.newurl;
Query OK, 5 rows affected (0.02 sec)
Rows matched: 5 Changed: 5 Warnings: 0
mysql> select * from todd;
+----+-----------------------------------------------------------------------------------------+
| id | url |
+----+-----------------------------------------------------------------------------------------+
| 1 | <img height="319" alt="" src="http://www.example.com/images/myexample.jpg" width="496"> |
| 2 | <img height="329" alt="" src="http://www.example.com/images/myexample.jpg" width="130"> |
| 3 | <img height="339" alt="" src="http://www.example.com/images/myexample.jpg" width="206"> |
| 4 | <img height="349" alt="" src="http://www.example.com/images/myexample.jpg" width="498"> |
| 5 | <img height="359" alt="" src="http://www.example.com/images/myexample.jpg" width="499"> |
+----+-----------------------------------------------------------------------------------------+
5 rows in set (0.01 sec)
mysql> select * from todd;
试试看!!!
警告
如果发布真正的表结构,我将为该表编写正确的SQL如果多次运行查询,则在第一次更改后不会更改任何其他内容