3

我有一张桌子

'310', 'D', '1', '0', 'Clowns.jpg', ?, '63527560196'
'311', 'D', '1', '1', 'Clowns_102_x_102.jpg', ?, '63527560197'
'312', 'D', '1', '1', 'Clowns_45_x_45.jpg', ?, '63527560197'
'313', 'D', '1', '1', 'Clowns_80_x_80.jpg', ?, '63527560197'
'314', 'D', '1', '1', 'Clowns_120_x_120.jpg', ?, '63527560198'
'315', 'D', '1', '1', 'Clowns_180_x_180.jpg', ?, '63527560198'
'316', 'D', '1', '1', 'Clowns_300_x_300.jpg', ?, '63527560198'

我想将名为 Clowns 的文件重命名为 Clowning,以便数据看起来像这样

'310', 'D', '1', '0', 'Clowning.jpg', ?, '63527560196'
'311', 'D', '1', '1', 'Clowning_102_x_102.jpg', ?, '63527560197'
'312', 'D', '1', '1', 'Clowning_45_x_45.jpg', ?, '63527560197'
'313', 'D', '1', '1', 'Clowning_80_x_80.jpg', ?, '63527560197'
'314', 'D', '1', '1', 'Clowning_120_x_120.jpg', ?, '63527560198'
'315', 'D', '1', '1', 'Clowning_180_x_180.jpg', ?, '63527560198'
'316', 'D', '1', '1', 'Clowning_300_x_300.jpg', ?, '63527560198'

所以我尝试了这个

UPDATE new_images 
SET 
filespec = 'clowns100' + MID(filespec, 7, LENGTH(filespec) - 6);

然而我得到了

错误代码:1292。截断不正确的 DOUBLE 值:“小丑100”

4

2 回答 2

4

采用REPLACE

UPDATE new_images SET filespec = REPLACE(filespec, 'Clowns','Clowning')

更新 1

您查询的等效 mysql 代码是

UPDATE new_images 
SET filespec = CONCAT('clowns100', MID(filespec, 7, CHAR_LENGTH(filespec) - 6));
于 2013-02-08T16:44:27.330 回答
1

您可以在 SQL 中使用子字符串

 UPDATE new_images SET filespec = 'Clowning'+substring('Clowns.jpg', 7, len('Clowns.jpg') - 6) where filespec like 'Clowns%'
于 2013-02-08T17:00:27.423 回答