Home > Database > Mysql Tutorial > mysql存储过程中使用变量批量修改数据_MySQL

mysql存储过程中使用变量批量修改数据_MySQL

WBOY
Release: 2016-06-01 13:42:25
Original
1544 people have browsed it

bitsCN.com
mysql存储过程中使用变量批量修改数据 BEGIN declare i int;#查找表的列数 declare column_name_temp varchar(100);##查找表的列名 DECLARE column_un_change varchar(100); DECLARE table_temp_name varchar(100); declare description varchar(100); declare code varchar(100); set column_un_change = 'OTHER_INCOME'; set description='description'; set code = 'code';    set table_temp_name  = 'wy_notebill_detail2';  ######################查找表的列名存储到临时表################### drop table if EXISTS update_column; create temporary table update_column (a INT NOT NULL AUTO_INCREMENT,PRIMARY KEY (a)) TYPE = MyISAM SELECT column_name from information_schema.`COLUMNS` where table_name = table_temp_name and column_name not in(column_un_change,description,code) and data_type not in ('date','datetime'); #######################统计列数量#################### SELECT count(*) into i from update_column; SELECT i;    loop1: WHILE i>2 DO   ##########################给变量赋值列名####################### SELECT column_name into column_name_temp from update_column where a = i; SET i=i-1;   #########################更新表的数据########################## set @sqls=concat('update ',table_temp_name ,' set ',column_name_temp,' = 0'); PREPARE stmt1 from @sqls; EXECUTE stmt1 ; END WHILE loop1;   #SELECT * from wy_notebill_detail; END  作者 刘宗才 bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template