- (?) :
with
constants ( x, y, z ) as (
select 0.5 * ( 1 + sqrt(5) ),
0.5 * ( 1 - sqrt(5) ),
sqrt(5)
from dual
)
select level as seq, round( ( power(x, level - 1) - power(y, level - 1) ) / z ) as fib
from constants
connect by level < 195
;
, ; . , , ROUND(...), , .
EDIT. OP . , OP .
Execution Plan
Plan hash value: 1236776825
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
|* 1 | CONNECT BY WITHOUT FILTERING| | | | |
| 2 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(LEVEL<195)
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
6306 bytes sent via SQL*Net to client
684 bytes received via SQL*Net from client
14 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
194 rows processed
№ 2
, . , - , . (); - .
with
constants ( x, y, z ) as (
select 0.5 * ( 1 + sqrt(5) ),
0.5 * ( 1 - sqrt(5) ),
sqrt(5)
from dual
),
powers ( n ) as (
select 14 * a.p + b.q
from (select level - 1 p from dual connect by level <= 14) a
cross join
(select level - 1 q from dual connect by level <= 14) b
)
select n + 1 as seq, round( ( power(x, n) - power(y, n) ) / z ) as fib
from constants cross join powers
where n < 195
;
source
share