就是想实现使用存储过程来插入数据 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的中文问题
- 看一下这段SQL哪儿错了?
- MySQL数据库 select不到内容
- 帮忙写一个通过父节点ID查询所有子节点ID的SQL
- ===============mysql 取离现在时间最近的数据===========
- MYSQL 4.1乱码问题,弄了一天了中文还显示???????急死了
- MYSQL进程问题
- 在MYSQL中,如何将一个检索出来的结果集,再次进行检索?
- Mysql多个表数据量之和的统计
- 自己写了个php重置游戏内角色技能及天赋的功能,但是在PHP内无法执行,SQL语句在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;
错误信息如下