我想创建5个字符串顺序数据,例如

aaaaa
aaaab
aaaac


.... 取决于

zzzzx
zzzzy
zzzzz


sql是否有任何功能可以帮助我进行顺序数据生成?

目前我有四位数的顺序数据,如何生成五位数的顺序数据?

我有的

aaaa
aaab
aaac


....取决于

zzzx
zzzy
zzzz


我编写了以下过程,但要花很长时间才能完成..任何人都可以帮助我重写该过程或建议其他方法。

CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`()
BEGIN

      DECLARE a INT Default 1 ;
      DECLARE  tran varchar(255) Default 'aaaa';
      simple_loop: LOOP
         SET a=a+1;
         SET tran = (select fourth from m where idm=a);
         Insert into test.qwe(zxc) values (CONCAT(tran,'a'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'b'));
        Insert into test.qwe(zxc) values (CONCAT(tran,'c'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'d'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'e'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'f'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'g'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'h'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'i'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'j'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'k'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'l'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'m'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'n'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'o'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'p'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'q'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'r'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'s'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'t'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'u'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'v'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'w'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'x'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'y'));
         Insert into test.qwe(zxc) values (CONCAT(tran,'z'));
         IF a=1 THEN
            LEAVE simple_loop;
         END IF;
   END LOOP simple_loop;

END

最佳答案

从头开始:

CREATE TABLE alpha (a CHAR(1) NOT NULL);

INSERT INTO alpha (a) VALUES
  ('a'), ('b'), ('c'), ('d'), ('e'), ('f'),
  ('g'), ('h'), ('i'), ('j'), ('k'), ('l'),
  ('m'), ('n'), ('o'), ('p'), ('q'), ('r'),
  ('s'), ('t'), ('u'), ('v'), ('w'), ('x'),
  ('y'), ('z');

CREATE TABLE qwe (zxc CHAR(5) NOT NULL);

INSERT INTO qwe (zxc)
SELECT CONCAT(a1.a, a2.a, a3.a, a4.a, a5.a)
FROM alpha a1, alpha a2, alpha a3, alpha a4, alpha a5;


如果表中已经有所有长度为4的字符串,则只需连接一次alpha并将这些值连接起来即可生成所有长度为5的字符串。这仍然需要花费一些时间,无法解决。

07-28 12:50