【发布时间】:2015-10-06 10:34:57
【问题描述】:
我想创建 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
【问题讨论】:
-
您必须为此编写自己的代码。尽管可以使您的代码更智能一点,但可以使用 base(26) (a=1, b=2,...,z=26),从 0101010101 (aaaaa) 开始,然后一直加 1 直到您点击2626262626 (zzzzz)
-
即 11,881,376 行。任何方法保存数据都需要时间。
标签: mysql database mysql-workbench procedure sql-function