在线等,mysql循环插入测试数据,高手指点一下
set @v_index=0;
while @v_index<100000 do
set @v_index=@v_index+1
insert into myindex (vc_name,vc_city,i_age,i_schoolid) values('name'+@v_index,'city'+@v_index,12,@v_index)
end while;
想插入10万条测试数据,想直接在查询里面写sql语句,不想用存储过程,sql语句如上,报错,提示
[Err] 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 @v_index<100000 do
set @v_index=@v_index+1
insert into myindex (vc_name,' at line 1
高手指点一下,在mysql查询里面可以直接这么写么,如果可以,请指教。
------解决方案--------------------
DELIMITER $$
CREATE PROCEDURE DD()
BEGIN
SET @v_index=0;
WHILE @v_index<100000 DO
SET @v_index=@v_index+1;
INSERT INTO myindex (vc_name,vc_city,i_age,i_schoolid) VALUES('name'+@v_index,'city'+@v_index,12,@v_index) ;
END WHILE;
END $$
DELIMITER ;
------解决方案--------------------MYSQL 与ORALCE或者SQL SERVER不同,它的这种过程语句比如WHILE, REPEAT只能放在存储过程中执行。不能当作普通语句执行。