0

我有一个名为“URL”的列的数据库,我想将所有行从http://site.com更改为 www.site.com。我只想删除 http:// 并替换为 www。在每一行。这可以通过查询还是我需要手动更改它们?

4

2 回答 2

1

You don't specify the DBMS you're using, but I would think this sort of solution would work - most anything should have equivalent functions/operators (the below is Oracle SQL):

UPDATE table_name
   SET url = CONCAT( 'www.', SUBSTR(url, 8, LENGTH(url) - 7) )
 WHERE url LIKE 'http://%'
于 2012-09-06T01:59:00.327 回答
1

这是你想要的吗?你能详细说明你的问题吗?

UPDATE tableName
SET `URL` = 'www.site.com'
WHERE `URL` = 'http://site.com'

如何使用REPLACE

UPDATE tableName
SET `URL` = REPLACE(LOWER(`URL`), 'http://','www')

我添加了LOWER()功能,因为REPLACE()它区分大小写。

于 2012-09-06T01:54:19.493 回答