我的表中有一列名为 title_id,带有一些标题 ID。每个游戏 ID 的存储方式都像
title_1
title_2
title_3
其中 1、2、3 是标题的实际 ID。我想从所有记录中删除" title_ "文本。我有大约 5000 条记录,所以我无法手动编辑它们。
我如何使用查询来做到这一点。
提前致谢
Update table_name set `title_id` = REPLACE(`title_id`,'title_','');
我没有测试它.请检查
UPDATE table_name SET title_id = REPLACE(title_id, 'title_','')
查看REPLACE
函数。您可以执行以下操作:
UPDATE table
SET title_id = REPLACE(title_id, 'title_', '');
(啊,请务必首先通过运行SELECT
查询来测试您的UPDATE
查询!
尝试类似
update table_name set id=substring(id, from length('title_'))
where id like 'title%';
我没有对此进行测试,因为我在这里没有可用的MySQL数据库。子字符串函数的语法来自 MySQL 文档。