首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >顺序数据生成

顺序数据生成
EN

Stack Overflow用户
提问于 2015-07-16 19:55:49
回答 2查看 101关注 0票数 1

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

代码语言:javascript
复制
aaaaa
aaaab
aaaac

……上至

代码语言:javascript
复制
zzzzx
zzzzy
zzzzz

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

目前我有四位序贯数据,怎样才能生成五位数顺序数据?

我所拥有的

代码语言:javascript
复制
aaaa
aaab
aaac

....upto

代码语言:javascript
复制
zzzx
zzzy
zzzz

我写了下面的程序,但要花很长时间才能完成。有人能帮我重写程序或者建议不同的方法吗?

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-16 20:20:55

从头开始:

代码语言:javascript
复制
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的所有字符串。这仍然需要一些时间,无法避免。

票数 0
EN

Stack Overflow用户

发布于 2015-07-17 21:23:00

我写的sql过程有效..。花了大约4到5个小时,波普尔塔26x26x26x26组合了6个字串。

谢谢你的建议!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31463390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档