<legend id='2JZDQ'><style id='2JZDQ'><dir id='2JZDQ'><q id='2JZDQ'></q></dir></style></legend>
<tfoot id='2JZDQ'></tfoot>
    <bdo id='2JZDQ'></bdo><ul id='2JZDQ'></ul>

<i id='2JZDQ'><tr id='2JZDQ'><dt id='2JZDQ'><q id='2JZDQ'><span id='2JZDQ'><b id='2JZDQ'><form id='2JZDQ'><ins id='2JZDQ'></ins><ul id='2JZDQ'></ul><sub id='2JZDQ'></sub></form><legend id='2JZDQ'></legend><bdo id='2JZDQ'><pre id='2JZDQ'><center id='2JZDQ'></center></pre></bdo></b><th id='2JZDQ'></th></span></q></dt></tr></i><div id='2JZDQ'><tfoot id='2JZDQ'></tfoot><dl id='2JZDQ'><fieldset id='2JZDQ'></fieldset></dl></div>

  • <small id='2JZDQ'></small><noframes id='2JZDQ'>

        在 MySQL 中生成一系列数字

        时间:2023-08-18
          <tbody id='HfJxc'></tbody>
          <legend id='HfJxc'><style id='HfJxc'><dir id='HfJxc'><q id='HfJxc'></q></dir></style></legend>
          • <bdo id='HfJxc'></bdo><ul id='HfJxc'></ul>

              • <i id='HfJxc'><tr id='HfJxc'><dt id='HfJxc'><q id='HfJxc'><span id='HfJxc'><b id='HfJxc'><form id='HfJxc'><ins id='HfJxc'></ins><ul id='HfJxc'></ul><sub id='HfJxc'></sub></form><legend id='HfJxc'></legend><bdo id='HfJxc'><pre id='HfJxc'><center id='HfJxc'></center></pre></bdo></b><th id='HfJxc'></th></span></q></dt></tr></i><div id='HfJxc'><tfoot id='HfJxc'></tfoot><dl id='HfJxc'><fieldset id='HfJxc'></fieldset></dl></div>

                <tfoot id='HfJxc'></tfoot>

                <small id='HfJxc'></small><noframes id='HfJxc'>

                  本文介绍了在 MySQL 中生成一系列数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何从 MySQL 查询生成一系列连续数字(每行一个),以便将它们插入表中?

                  How do I generate a range of consecutive numbers (one per line) from a MySQL query so that I can insert them into a table?

                  例如:

                  nr
                  1
                  2
                  3
                  4
                  5
                  

                  为此我只想使用 MySQL(而不是 PHP 或其他语言).

                  I would like to use only MySQL for this (not PHP or other languages).

                  推荐答案

                  如果您需要表中的记录,并且想要避免并发问题,请按以下步骤操作.

                  If you need the records in a table and you want to avoid concurrency issues, here's how to do it.

                  首先你创建一个表来存储你的记录

                  First you create a table in which to store your records

                  CREATE TABLE `incr` (
                    `Id` int(11) NOT NULL auto_increment,
                    PRIMARY KEY  (`Id`)
                  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
                  

                  第二次创建一个这样的存储过程:

                  Secondly create a stored procedure like this:

                  DELIMITER ;;
                  CREATE PROCEDURE dowhile()
                  BEGIN
                    DECLARE v1 INT DEFAULT 5;
                    WHILE v1 > 0 DO
                      INSERT incr VALUES (NULL);
                      SET v1 = v1 - 1;
                    END WHILE;
                  END;;
                  DELIMITER ;
                  

                  最后调用 SP:

                  CALL dowhile();
                  SELECT * FROM incr;
                  

                  结果

                  Id
                  1
                  2
                  3
                  4
                  5
                  

                  这篇关于在 MySQL 中生成一系列数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:子查询与连接 下一篇:模拟 MySQL 中的滞后函数

                  相关文章

                  最新文章

                  <tfoot id='1O5wT'></tfoot>
                  <i id='1O5wT'><tr id='1O5wT'><dt id='1O5wT'><q id='1O5wT'><span id='1O5wT'><b id='1O5wT'><form id='1O5wT'><ins id='1O5wT'></ins><ul id='1O5wT'></ul><sub id='1O5wT'></sub></form><legend id='1O5wT'></legend><bdo id='1O5wT'><pre id='1O5wT'><center id='1O5wT'></center></pre></bdo></b><th id='1O5wT'></th></span></q></dt></tr></i><div id='1O5wT'><tfoot id='1O5wT'></tfoot><dl id='1O5wT'><fieldset id='1O5wT'></fieldset></dl></div>

                      <bdo id='1O5wT'></bdo><ul id='1O5wT'></ul>

                      <small id='1O5wT'></small><noframes id='1O5wT'>

                    1. <legend id='1O5wT'><style id='1O5wT'><dir id='1O5wT'><q id='1O5wT'></q></dir></style></legend>