就是想实现使用存储过程来插入数据 start参数:是来控制从id为几开始插入, max_num是来控制插入的条数
delimiter $$
create procedure insert_user(in start int(10),in max_num int(10))
begin
declare i int default 0;
set autocommit=0;
repeat
set i=i+1;
insert into user_list values((start+i),2,(start+i),md5(123));
until i=max_num;
end repeat;
commit;
end $$
不懂哪里出错了,错误提示如下
delimiter $$
create procedure insert_user(in start int(10),in max_num int(10))
begin
declare i int default 0;
set autocommit=0;
repeat
set i=i+1;
insert into user_list values((start+i),2,(start+i),md5(123));
until i=max_num;
end repeat;
commit;
end $$
不懂哪里出错了,错误提示如下
解决方案 »
- mysql自定义函数的问题 SOS
- 怎么把视图存为一张单表?
- 新手请教一小问题(在线等待)。
- 在线,十万万火急,明天合同到期,mySQl中一时间段查询的问题,请高手指教
- 请高手指教delphi操作postgresql问题,百分相赠,在线等待
- 怎么样把MYSQL加载到管理工具中的服务项呀
- Mysql中如果count()函数出来的是0则没有返回记录,有没有什么方法可以使得它变得有返回
- 请教一个关于mysql的问题
- mysql 可以给临时表创建自增Id吗
- mysql中如何结合表中字段的原有数据进行批量更新
- MySQL中类型隐身转换求解!!视图中的union
- java 连接Mysql java.net.SocketException: Software caused connection abort: socket
create procedure insert_user(start int, max_num int)
begin
declare i int default 0;
set autocommit=0;
test:repeat
set i=i+1;
insert into user_list values((start+i),2,(start+i),md5(123));
until i=max_num
end repeat test;
commit;
end $$
CREATE PROCEDURE insert_user(IN START INT(10),IN max_num INT(10))
BEGIN
DECLARE i INT DEFAULT 0;
SET autocommit=0;
WHILE i<max_num DO
INSERT INTO user_list VALUES((`start`+i),2,(`start`+i),MD5('123'));
SET i=i+1;
END WHILE;
COMMIT;
END $$
CREATE
PROCEDURE insert_user(IN start INT(10), IN `max_num ` INT(10))
BEGIN
DECLARE i INT DEFAULT 0; SET autocommit = 0;
REPEAT
SET i = i + 1;
INSERT INTO user_list VALUES ((start + i), 2, (start + i), md5(123));
UNTIL i = max_num
END REPEAT;
COMMIT;END
create procedure insert_user(start int, max_num int)
begin
declare i int default 0;
set autocommit=0;
test:repeat
set i=i+1;
insert into user_list values((start+i),2,(start+i),md5(123));
until i=max_num
end repeat test;
commit;
end $$执行上面的语句完,错误信息如下(我是在wamp环境中的mysql执行的,不是命令行)
—————————————————————————————————————————————————
错误
SQL 查询:CREATE PROCEDURE insert_user( START INT, max_num INT ) BEGIN declare i INT DEFAULT 0;SET AUTOCOMMIT =0;test : repeat SET i = i +1;INSERT INTO user_list
VALUES ((START + i
), 2, (START + i
), MD5( 123 )
);until i = max_num END repeat test;COMMIT ;END $$
MySQL 返回:#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$$' at line 11
————————————————————————————————————————————————
你也可以 把 “$$ ”换成成 “ ; ”试试看吧
BEGIN
declare i INT DEFAULT 0;SET AUTOCOMMIT =0;test : repeat SET i = i +1;INSERT INTO user_list
VALUES ((START + i
), 2, (START + i
), MD5( 123 )
);until i = max_num END repeat test;COMMIT ;END;
错误信息如下