循环Mysql以使用PhpMyadmin在表中插入数据 [英] Loop Mysql to insert data in table using PhpMyadmin
问题描述
您好,我试图在数据库中插入数据,以便为每个数字分配一个ID
Hi im trying to insert data in a database for asign an id to each number
table numbers
id | number
1 | 2560
2 | 2561
然后继续输入100个数字.我在PL/sql中找到了这个
And this go on for 100 numbers. i found this for PL/sql
BEGIN
FOR v_LoopCounter IN 2560..2660 LOOP
INSERT INTO numbers (number)
VALUES (v_LoopCounter);
END LOOP;
END;
也尝试过
BEGIN
FOR v_LoopCounter IN 2560.2660 LOOP;
INSERT INTO numbers (number);
VALUES (v_LoopCounter);
END LOOP;
END;
我该如何使用Phpmyadmin在Sql中执行此操作,这就是我可以使用的功能.
How can i do this in Sql using Phpmyadmin, for thats what i can use.
谢谢!
我试图在PHPMyadmin中运行此SQL,但是我总是遇到语法错误
I have tried to run this SQL in PHPMyadmin, but i always got a Syntax Error
您的SQL查询中似乎有一个错误.下面的MySQL服务器错误输出(如果有的话)也可以帮助您诊断问题
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
我现在也尝试过
SELECT * FROM table_name WHERE
BEGIN
FOR v_LoopCounter IN 2560..2660 LOOP
INSERT INTO numbers (number)
VALUES (v_LoopCounter);
END LOOP;
END;
推荐答案
尝试一下 首先选择一个数据库,否则会出现未选择数据库"错误
Try this SELECT a database first else you will get the no database selected error
DROP PROCEDURE IF EXISTS myFunction;
delimiter $$
CREATE PROCEDURE myFunction()
BEGIN
DECLARE i INT DEFAULT 1;
DECLARE j INT DEFAULT 0;
DROP TABLE IF EXISTS test;
CREATE TEMPORARY TABLE test
(id int, numbers int);
WHILE (i<=100) DO
SET j=i+2560;
INSERT INTO test VALUES(i,j);
SET i=i+1;
END WHILE;
select * from test;
drop table test;
END$$
在那之后调用程序
delimiter ;
call myFunction();
这篇关于循环Mysql以使用PhpMyadmin在表中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!