存储过程怎么运行多个insert/update?传入参数时怎么传?要求一个事务中完成,方便回滚。
解决方案 »
- 怎么让mysql查询的时候隔5个数据出现一次
- MySQLAdministrator无法编辑表中数据 系统找不到指定的文件
- mysql中不定参函数的实现。
- 对mysql的数据库表结构做了一些改变,能否像微软sql那样导出一个脚本来自动将这些改变更新到旧数据库上?
- 比较急的问题 (no lock)
- 一条难解的sql ,请高人帮手?
- 关于四表连接来达到横向显示同一个字段中不同的内容
- ~~~~~~~~~~SQL语句-难啊!难!难的不得了!~~~~~~~~~~~
- 帮忙看看这样的语句有没有问题
- sql 语句 统计求教
- 如何实现两个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;