with FIBONACCI (i, SPIRAL, PREV) as
(
select
1 i, 0 SPIRAL, cast(null as number) PREV
from
DUAL
union all
select
f1.i + 1 i, f1.SPIRAL + nvl(f1.PREV,1) SPIRAL, f1.SPIRAL PREV
from
FIBONACCI f1
where
f1.i < 605
)
select SPIRAL from FIBONACCI order by i;
The limit of 605 is the limit before numeric overflow.
Currently developing futuristic smart-device, IoT connected, highway construction site safety system in EU.
Used to work on infrastructure, application architecture and cloud engineering.
I haven't seen a SQL implementation yet, so here's one:
👏👏 I never thought you could do that with SQL!
Here it is in Oracle SQL:
The limit of 605 is the limit before numeric overflow.
Here's interesting one for SQL Server with maximum value before arithmetic overflow due to data type limit: