我用Delphi连接ACCESS数据库,库的格式是
NO 1 2 3 4 5 6 7 8 9 10
1 bc ab bc ac abc ac ab bc ac ab
2 ac abc ab bc ac ab ab bc abc ab
3 ab bc abc ab abc ac bc ac abc ac
4 abc ab bc bc ac ab ab ab ac bc
....
怎样在delphi中用程序实现每个字段的组合并存入ACCESS数据库的表中!如从第一条记录抽取每个字段的最后一个字母得到的一个组合为
NO 1 2 3 4 5 6 7 8 9 10
1 c b c c c c b c c b
....
第一条记录共得到2*2*2*2*3*2*2*2*2*2=1536个组合,
然后再到第二条记录,如此到表的最后一条记录!
NO 1 2 3 4 5 6 7 8 9 10
1 bc ab bc ac abc ac ab bc ac ab
2 ac abc ab bc ac ab ab bc abc ab
3 ab bc abc ab abc ac bc ac abc ac
4 abc ab bc bc ac ab ab ab ac bc
....
怎样在delphi中用程序实现每个字段的组合并存入ACCESS数据库的表中!如从第一条记录抽取每个字段的最后一个字母得到的一个组合为
NO 1 2 3 4 5 6 7 8 9 10
1 c b c c c c b c c b
....
第一条记录共得到2*2*2*2*3*2*2*2*2*2=1536个组合,
然后再到第二条记录,如此到表的最后一条记录!
Connected to Oracle9i Enterprise Edition Release 9.2.0.1.0
Connected as cvbom
SQL>
SQL> select *
2 from (select substr(x, rownum, 1)
3 from (select 'bc' x from dual)
4 connect by rownum <= length(x)) t1,
5 (select substr(x, rownum, 1)
6 from (select 'ab' x from dual)
7 connect by rownum <= length(x)) t2,
8 (select substr(x, rownum, 1)
9 from (select 'bc' x from dual)
10 connect by rownum <= length(x)) t3,
11 (select substr(x, rownum, 1)
12 from (select 'ac' x from dual)
13 connect by rownum <= length(x)) t4,
14 (select substr(x, rownum, 1)
15 from (select 'abc' x from dual)
16 connect by rownum <= length(x)) t5,
17 (select substr(x, rownum, 1)
18 from (select 'ac' x from dual)
19 connect by rownum <= length(x)) t6,
20 (select substr(x, rownum, 1)
21 from (select 'ab' x from dual)
22 connect by rownum <= length(x)) t7,
23 (select substr(x, rownum, 1)
24 from (select 'bc' x from dual)
25 connect by rownum <= length(x)) t8,
26 (select substr(x, rownum, 1)
27 from (select 'ac' x from dual)
28 connect by rownum <= length(x)) t9,
29 (select substr(x, rownum, 1)
30 from (select 'ab' x from dual)
31 connect by rownum <= length(x)) t10;SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1) SUBSTR(X,ROWNUM,1)
------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------
b a b a a a a b a a
c a b a a a a b a a
b b b a a a a b a a
c b b a a a a b a a
b a c a a a a b a a
c a c a a a a b a a
b b c a a a a b a a
c b c a a a a b a a
b a b c a a a b a a
…………1536 rows selectedSQL>
var
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10: pChar;
slResult, slRow: TStringList;
i: Integer;
begin
//bc ab bc ac abc ac ab bc ac ab slResult := TStringList.Create; p1 := pChar('bc');
while not (p1^ = #0) do
begin
p2 := pChar('ab');
while not (p2^ = #0) do
begin
p3 := pChar('bc');
while not (p3^ = #0) do
begin
p4 := pChar('ac');
while not (p4^ = #0) do
begin
p5 := pChar('abc'); while not (p5^ = #0) do
begin
p6 := pChar('ac');
while not (p6^ = #0) do
begin
p7 := pChar('ab');
while not (p7^ = #0) do
begin
p8 := pChar('bc');
while not (p8^ = #0) do
begin
p9 := pChar('ac');
while not (p9^ = #0) do
begin
p10 := pChar('ab');
while not (p10^ = #0) do
begin
slRow := TStringList.Create;
slRow.Add(p1^);
slRow.Add(p2^);
slRow.Add(p3^);
slRow.Add(p4^);
slRow.Add(p5^);
slRow.Add(p6^);
slRow.Add(p7^);
slRow.Add(p8^);
slRow.Add(p9^);
slRow.Add(p10^);
slResult.AddObject('', slRow); inc(p10);
end;
inc(p9);
end;
inc(p8);
end;
inc(p7);
end;
inc(p6);
end;
inc(p5);
end;
inc(p4);
end;
inc(p3);
end;
inc(p2);
end;
inc(p1);
end;
for i := 0 to slResult.Count - 1 do
begin
with ListView1.Items.Add do
begin
Caption := IntToStr(i + 1);
SubItems := TStringList(slResult.Objects[i]);
end;
end;
end;
var
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10: pChar;
slResult, slRow: TStringList;
i: Integer;
begin
//bc ab bc ac abc ac ab bc ac ab slResult := TStringList.Create; p1 := pChar('bc');
while not (p1^ = #0) do
begin
p2 := pChar('ab');
while not (p2^ = #0) do
begin
p3 := pChar('bc');
while not (p3^ = #0) do
begin
p4 := pChar('ac');
while not (p4^ = #0) do
begin
p5 := pChar('abc'); while not (p5^ = #0) do
begin
p6 := pChar('ac');
while not (p6^ = #0) do
begin
p7 := pChar('ab');
while not (p7^ = #0) do
begin
p8 := pChar('bc');
while not (p8^ = #0) do
begin
p9 := pChar('ac');
while not (p9^ = #0) do
begin
p10 := pChar('ab');
while not (p10^ = #0) do
begin
slRow := TStringList.Create;
slRow.Add(p1^);
slRow.Add(p2^);
slRow.Add(p3^);
slRow.Add(p4^);
slRow.Add(p5^);
slRow.Add(p6^);
slRow.Add(p7^);
slRow.Add(p8^);
slRow.Add(p9^);
slRow.Add(p10^);
slResult.AddObject('', slRow); inc(p10);
end;
inc(p9);
end;
inc(p8);
end;
inc(p7);
end;
inc(p6);
end;
inc(p5);
end;
inc(p4);
end;
inc(p3);
end;
inc(p2);
end;
inc(p1);
end;
for i := 0 to slResult.Count - 1 do
begin
with ListView1.Items.Add do
begin
Caption := IntToStr(i + 1);
SubItems := TStringList(slResult.Objects[i]);
end;
end;
end;
for i1:=1 to length(s1) do
for i2:=1 to length(s2) do
for i3:=1 to length(s3) do
for i4:=1 to length(s4) do
for i5:=1 to length(s5) do
for i6:=1 to length(s6) do
for i7:=1 to length(s7) do
for i8:=1 to length(s8) do
for i9:=1 to length(s9) do
for i10:=1 to length(s10) do
begin
query.sql.text :='insert into newtable (p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) '+
'values(:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10)';
paramsbyname('p1').value := s1[i1];
paramsbyname('p2').value := s2[i2];
......
query.execsql;
end;