存储过程怎么运行多个insert/update?传入参数时怎么传?要求一个事务中完成,方便回滚。 存储过程怎么运行多个insert/update?传入参数时怎么传?要求一个事务中完成,方便回滚。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 START TRANSACTIONinsert/updatecommit 存储过程怎么运行多个insert/update?这个你直接在事务中就行了。传入参数时怎么传?你的具体需要是什么?在存储过程开始就需要传入所有的参数,无法执行一半再等你传其它参数。 MYSQL本身并不支持数组。没有什么好办法。或者用你的程序来实现。或者用存储过程,传入一个字符串,字符串中包含你所有的数组数据。比如 'A1,100,A2,200,A5,700' 这种方法传入A1,100A2,200A5,700 MYSQL没有数组,要么一个一个传入OR存入临时表再做处理 drop procedure if exists fileInsertProc; create procedure fileInsertProc(In val1 varchar(30),In val2 varchar(30),In val3 varchar(30),In val4 varchar(30),In val5 int) begin insert into upload(fileName,fileUrl)values(val1,val2); insert into file(fileTitle,fileKind,userId,uploadId)values(val3,val4,val5,LAST_INSERT_ID());end;这样可以传入多个参数 drop procedure if exists fileInsertProc; create procedure fileInsertProc(In val1 varchar(30),In val2 varchar(30),In val3 varchar(30),In val4 varchar(30),In val5 int) begin insert into upload(fileName,fileUrl)values(val1,val2); insert into file(fileTitle,fileKind,userId,uploadId)values(val3,val4,val5,LAST_INSERT_ID());end; 要是有规律的话,你弄个循环,在循环里面执行insert、update。declare exit handler for sqlexception rollback;start transaction;commit; Out of range value for column 'tel' at row 1 Mysql 二进制文件生成问题 trigger问题,检测一个值是否存在另个有表中 MY SQL特别的问题 java- mysql5.0 连接问题! 在线等! linux下用C编程访问mysql数据库,编译报错 求助 sqlite3模糊查询的问题 怎样让mysql支持特殊字符? Mysql死锁问题 如何实现两个mysql数据库内两张表的自动定时同步? 运行MySQL Command Line Client时一闪而过,开始安装的是很正常
insert/update
commit
这个你直接在事务中就行了。传入参数时怎么传?
你的具体需要是什么?在存储过程开始就需要传入所有的参数,无法执行一半再等你传其它参数。
没有什么好办法。或者用你的程序来实现。或者用存储过程,传入一个字符串,字符串中包含你所有的数组数据。比如 'A1,100,A2,200,A5,700' 这种方法传入
A1,100
A2,200
A5,700
MYSQL没有数组,要么一个一个传入OR
存入临时表再做处理
create procedure fileInsertProc(In val1 varchar(30),In val2 varchar(30),In val3 varchar(30),In val4 varchar(30),In val5 int)
begin
insert into upload(fileName,fileUrl)values(val1,val2);
insert into file(fileTitle,fileKind,userId,uploadId)values(val3,val4,val5,LAST_INSERT_ID());
end;这样可以传入多个参数
create procedure fileInsertProc(In val1 varchar(30),In val2 varchar(30),In val3 varchar(30),In val4 varchar(30),In val5 int)
begin
insert into upload(fileName,fileUrl)values(val1,val2);
insert into file(fileTitle,fileKind,userId,uploadId)values(val3,val4,val5,LAST_INSERT_ID());
end;
declare exit handler for sqlexception rollback;
start transaction;commit;