Test #1:
I have a user-defined function and a CONNECT BY LEVEL query:
with function custom_function(p_id in number) return number
is
begin
return p_id;
end;
select
custom_function(level)
from
dual
connect by level <= 1000
ID
--
1
2
3
4
5
6
7
8
9
10
...
10 rows of 1000
That non-deterministic function work as expected. It returns sequential numbers, similar to if the function wasn't used.
Test #2:
This test is the same as the first, except the function is deterministic:
with function custom_function(p_id in number) return number
deterministic is --this is what I changed
begin
return p_id;
end;
select
custom_function(level) id
from
dual
connect by level <= 1000
ID
--
1
1
1
1
1
1
1
1
1
1
...
10 rows of 1000
That deterministic function doesn't work as expected. Unlike test #1, it doesn't return sequential numbers. If we look at the full resultset, it returns:
1
x 100101
x 100202
x 100303
x 100404
x 100505
x 100606
x 100707
x 100808
x 100909
x 100
Why does the DETERMINISTIC function return unexpected numbers in the CONNECT BY LEVEL query?