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:
1x 100101x 100202x 100303x 100404x 100505x 100606x 100707x 100808x 100909x 100
Why does the DETERMINISTIC function return unexpected numbers in the CONNECT BY LEVEL query?