|
|
为什么connect_by_path算出来的t记录要多3000多?
SQL> set timi on
SQL> set lines 132 pages 50000
SQL> with t as(select x from (select to_char(level-1,'fmxxxx') x from dual connect by level<=65536)
2 where substr(x,1,1)<>substr(x,2,1) and substr(x,1,1)<>substr(x,3,1) and substr(x,1,1)<>substr(x,4,1)
3 and substr(x,2,1)<>substr(x,3,1) and substr(x,2,1)<>substr(x,4,1) and substr(x,3,1)<>substr(x,4,1)
4 )
5 select count(*) from t;
COUNT(*)
----------
40950
已用时间: 00: 00: 00.21
SQL> with t as(select x from (select to_char(level-1,'fmxxxx') x from dual connect by level<=65536)
2 where substr(x,1,1)<>substr(x,2,1) and substr(x,1,1)<>substr(x,3,1) and substr(x,1,1)<>substr(x,4,1)
3 and substr(x,2,1)<>substr(x,3,1) and substr(x,2,1)<>substr(x,4,1) and substr(x,3,1)<>substr(x,4,1)
4 )
5 select sum(length(x))/4 from t;
SUM(LENGTH(X))/4
----------------
40950
已用时间: 00: 00: 00.21
---
SQL> create table t AS (SELECT REPLACE(SYS_CONNECT_BY_PATH(rn,','),',') x
2 FROM (SELECT to_char(ROWNUM-1,'fmx') rn FROM DUAL CONNECT BY ROWNUM<=16)
3 WHERE LEVEL=4
4 CONNECT BY NOCYCLE rn<> PRIOR rn AND LEVEL<=4
5 );
表已创建。
已用时间: 00: 00: 00.57
SQL> select count(*)from t;
COUNT(*)
----------
43680
是自己写错了,速度还是不用connect_by_path快
SQL> with t as(select x from (select to_char(level-1,'fm0xxx') x from dual connect by level<=65536)
2 where substr(x,1,1)<>substr(x,2,1) and substr(x,1,1)<>substr(x,3,1) and substr(x,1,1)<>substr(x,4,1)
3 and substr(x,2,1)<>substr(x,3,1) and substr(x,2,1)<>substr(x,4,1) and substr(x,3,1)<>substr(x,4,1)
4 )
5 select count(*) from t;
COUNT(*)
----------
43680
已用时间: 00: 00: 00.21
SQL> with t AS (SELECT REPLACE(SYS_CONNECT_BY_PATH(rn,','),',') x
2 FROM (SELECT to_char(ROWNUM-1,'fmx') rn FROM DUAL CONNECT BY ROWNUM<=16)
3 WHERE LEVEL=4
4 CONNECT BY NOCYCLE rn<> PRIOR rn AND LEVEL<=4
5 )
6 select count(*) from t;
COUNT(*)
----------
43680
已用时间: 00: 00: 00.42
SQL>
SQL> /
COUNT(*)
----------
43680
已用时间: 00: 00: 00.40
SQL>
[ 本帖最后由 〇〇 于 2010-6-11 08:54 编辑 ] |
|