表中这三个字段unique_id(int), agent_id(varchar),agent_name(varchar),现在想批量插入一堆数据,unique_id让自增长就行,agent_id是数字,大概这个意思
begindeclare i int;
set i = 6001;
while i <= 6300 doinsert into agent a (a.unique_id,
a.agent_id,
a.agent_name)
values (i, ----------------------------这里不应该是i,但是不知道自增长的那种怎么写
i, ---------------------------这里不知道怎么弄了,字符型的怎么插入数字呢?
i);
set i=i+1; end while;
end;这个正确的写法是什么呢??
谢谢了
begindeclare i int;
set i = 6001;
while i <= 6300 doinsert into agent a (a.unique_id,
a.agent_id,
a.agent_name)
values (i, ----------------------------这里不应该是i,但是不知道自增长的那种怎么写
i, ---------------------------这里不知道怎么弄了,字符型的怎么插入数字呢?
i);
set i=i+1; end while;
end;这个正确的写法是什么呢??
谢谢了
a.agent_id,
a.agent_name)
values (
concat("'",i,"'"),
i);
values(i,i,i)
declare i int;
set i = 6001;
while i <= 6300 doinsert into agent a (a.agent_id, a.agent_name) values (cast(i as char(10),i);
set i=i+1; end while;
end;
declare i int;
set i = 6001;
while i <= 6300 do
insert into agent(unique_id,agent_id,agent_name) values (i,i,i);
set i=i+1;
end while;
end;
i, ----------------------------这里不应该是i,但是不知道自增长的那种怎么写
这个I你已经写成增长的了。 i, ---------------------------这里不知道怎么弄了,字符型的怎么插入数字呢?
MYSQL会自动转换
begin
declare i int;
set i = 6002;
while i < 6005 doinsert into ccone.agent
(AGENT_ID, AGENT_NAME, PASSWORD, TYPE_CODE, STATE)
values
(cast(i as char(20),
cast(i as char(30),
'e10adc3949ba59abbe56e057f20f883e',
'A',
'Y');
set i=i+1; end while;
end;我是这么写的,可是报错
Error Code : 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 'while i < 6005 doinsert into ccone.agent
(AGENT_ID, AGENT_NAME, PASSWORD' at line 1
(0 ms taken)
(AGENT_ID, AGENT_NAME, PASSWORD, TYPE_CODE, STATE)
values
(cast(i as char(20)),
cast(i as char(30)),
'e10adc3949ba59abbe56e057f20f883e',
'A',
'Y');
declare i int;
set i = 6002;
while i < 6005 do
insert into ccone.agent(AGENT_ID, AGENT_NAME, PASSWORD, TYPE_CODE, STATE)
values(cast(i as char(20)),
cast(i as char(30)),
'e10adc3949ba59abbe56e057f20f883e',
'A',
'Y');
set i=i+1;
end while;
end;
我把括号补充上了也不对,错误应该是在上面呢
Error Code : 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 'while i < 6005 doinsert into ccone.agent
(AGENT_ID, AGENT_NAME, PASSWORD' at line 1
(0 ms taken)
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 'declare i int' at line 2
(0 ms taken)是这个错误
CREATE PROCEDURE ff2()
BEGINDECLARE i INT;
SET i = 6002;
WHILE i < 6005 DOINSERT INTO ccone.agent
(AGENT_ID, AGENT_NAME, `PASSWORD`, TYPE_CODE, STATE)
VALUES
(CAST(i AS CHAR(20)),
CAST(i AS CHAR(30)),
'e10adc3949ba59abbe56e057f20f883e',
'A',
'Y');
SET i=i+1; END WHILE;
END$$
DELIMITER ;