顺序数据生成

时间:2015-07-16 19:55:50

标签: mysql database mysql-workbench procedure sql-function

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

aaaaa
aaaab
aaaac

.... upto

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

2 个答案:

答案 0 :(得分:0)

从头开始:

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的字符串。它仍然需要一些时间,没有办法解决这个问题。

答案 1 :(得分:0)

我写的sql程序工作..大约需要4-5个小时来完成6个字符串的26x26x26x26组合。

感谢所有的建议!