|
|
自己写错了,导致没用的def也混进了穷举范围,本来b:11800 结果 25701,时间翻了6倍
现在和SQL持平
- SQL> create or replace procedure pc5
- 2 as
- 3 time_before BINARY_INTEGER;
- 4 time_after BINARY_INTEGER;
- 5 TYPE t_num IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER ;
- 6 x t_num;
- 7 a t_num;
- 8 b t_num;
- 9 c PLS_INTEGER;
- 10 c1 PLS_INTEGER;
- 11 r PLS_INTEGER;
- 12 l varchar(4);
- 13 begin
- 14 c:=0;
- 15 time_before := DBMS_UTILITY.GET_TIME;
- 16 for i in to_number('1234','fm0xxx')..to_number('cba9','fm0xxx') loop
- 17 l:=to_char(i,'fm0xxx');
- 18 if substr(l,1,1)<>substr(l,2,1)and
- 19 substr(l,2,1)<>substr(l,3,1)and
- 20 substr(l,3,1)<>substr(l,4,1)and
- 21 substr(l,1,1)<>substr(l,3,1)and
- 22 substr(l,2,1)<>substr(l,4,1)and
- 23 substr(l,1,1)<>substr(l,4,1)and
- 24 instr(l,0)=0 and instr(l,'d')=0 and instr(l,'e')=0 and instr(l,'f')=0 then
- 25 c:=c+1;
- 26 if i<to_number('cba9','fm0xxx')/2 then
- 27 a(c):=i;
- 28 c1:=c;
- 29 end if;
- 30 b(c):=i;
- 31 x(i):=c;
- 32 else
- 33 x(i):=c;
- 34 end if;
- 35 end loop;
- 36 r:=0;
- 37 --dbms_output.put_line('c='||c||'c1='||c1||a(1)||b(1));
- 38 FOR I IN 1 .. c1 LOOP
- 39 FOR J IN x(a(i))+1 .. x(to_number('cba9','fm0xxx')-a(i)) LOOP
- 40 --if translate('123456789abc','$'||to_char(a(i),'fm0xxx')||to_char(b(j),'fm0xxx')||to_char(a(i)+b(j),'fm0xxx'),'$')is null then
- 41 --dbms_output.put_line(to_char(a(i),'fm0xxx')||to_char(b(j),'fm0xxx')||to_char(a(i)+b(j),'fm0xxx'));
- 42 --NULL;
- 43 l:=to_char(a(i)+b(j),'fm0xxx');
- 44 if substr(l,1,1)<>substr(l,2,1)and
- 45 substr(l,2,1)<>substr(l,3,1)and
- 46 substr(l,3,1)<>substr(l,4,1)and
- 47 substr(l,1,1)<>substr(l,3,1)and
- 48 substr(l,2,1)<>substr(l,4,1)and
- 49 substr(l,1,1)<>substr(l,4,1)and
- 50 instr(l,0)=0 and instr(l,'d')=0 and instr(l,'e')=0 and instr(l,'f')=0
- 51 and length(translate(to_char(a(i),'fm0xxx'),'$'||l,'$'))=4
- 52 and length(translate(to_char(b(j),'fm0xxx'),'$'||l,'$'))=4
- 53 and length(translate(to_char(a(i),'fm0xxx'),'$'||to_char(b(j),'fm0xxx'),'$'))=4 then
- 54 r:=r+1;
- 55 --dbms_output.put_line(r||':'||to_char(a(i),'fm0xxx')||to_char(b(j),'fm0xxx')||to_char(a(i)+b(j),'fm0xxx'));
- 56 end if;
- 57 end loop;
- 58 --if r>=1000 then
- 59 -- exit;
- 60 --end if;
- 61 end loop;
- 62
- 63 time_after := DBMS_UTILITY.GET_TIME;
- 64 DBMS_OUTPUT.PUT_LINE ('output:'||(time_after - time_before)||'rows:'||r);
- 65 end;
- 66 /
- 过程已创建。
- 已用时间: 00: 00: 00.05
- SQL> exec pc5;
- output:10228rows:3408
- PL/SQL 过程已成功完成。
- 已用时间: 00: 01: 42.27
- SQL>
复制代码 |
|