如何在mysql里面把表A中所有值后面加2q

来源:百度知道 编辑:UC知道 时间:2024/06/04 15:07:27
如何在mysql里面把表A中所有值后面加2q

update 表A set 列1=列1+'2q' ,列2=列2+'2q',……,列n=列n+'2q'

看你的表A中的字段属性是什么了,看你的问题似乎全是字符类型吧!建立个存储过程实现吧!大概格式:
假设表名mytable 其中一个字段名aaa~~~

delimiter $$
drop procedure if exists `myprocedure`$$
create procedure `myprocedure`()
begin
declare p_aaa character ( 10);
.
.
.
declare my_cursor cursor for select aaa,.... from mytable;
declare continue handler for sqlstate '02000' set flag = 1;
open my_cursor;
repeat
fetch my_cursor into
p_aaa,
.
.
.;
if not flag then
select concat(p_aaa, '2q') into p_aaa;
.
.
.
update mytable set aaa=p_aaa,........;
end if;
until flag end repeat;
close my_cursor;
end$$
delimiter ;

建立以后用call命令调用这个存储过程即可.
写的急,有错误的地方自己改改!