循环 MySQL 在表中插入数据 [英] Loop MySQL to insert data in table

查看:66
本文介绍了循环 MySQL 在表中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在数据库中插入数据,以便为每个数字分配一个 id

I'm trying to insert data in a database for assign 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 that's what I can use? I tried it but I get this 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;

推荐答案

--- 你不能在 PHPMyAdmin 中使用 FOR 循环 ---

使用这种方式:-

--- You can not use FOR loop in PHPMyAdmin ---

Use this way :-

  1. 打印所有查询并复制.

  1. Print all your queries and copy it.

将其粘贴到 sql 选项卡中,然后按 GO.

Paste it in sql tab and press GO.

完成.


示例:-

Done.


Example :-

 str = "";
 for (let i = 8; i < 77; i++) {
     str = str + "HERE IS YOU QUERY YOU WANT... Like DELETE FROM tabel_name WHERE column_id=+i+;\n"
 }
 console.log(str);

这篇关于循环 MySQL 在表中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆