Blame SQL*Plus, Ben. Your function works, in this situation, correctly. The extra value(1
) you see is there because of arraysize
value, and, mostly because of the way how SQL*Plus fetches rows. It first fetches first row and only then it starts to use arraysize
for subsequent fetches. Every new fetch is a new database call, which forces your deterministic function to be evaluated. Try to set the arraysize
to 1 or 2(same effect) and execute your select
statement. The first row returns, and then, arraysize
comes to play and each subsequent fetch will return couple of rows:
Arraysize
is set to 1(two in fact)
SQL> set arraysize 1;
SQL> select test_deterministic(n) from tmp_test;
TEST_DETERMINISTIC(N)
---------------------
1
2
3
4
0
1
2
3
4
0
10 rows selected.
1
2
3
4
0
1
2
3
4
0
Elapsed: 00:00:10.10
The same query with much larger arraysize
:
SQL> set arraysize 50;
SQL> select test_deterministic(n) from tmp_test;
TEST_DETERMINISTIC(N)
---------------------
1
2
3
4
0
1
2
3
4
0
10 rows selected.
1
2
3
4
0
1
Elapsed: 00:00:06.06
SQL> spool off;
Any other client, whether it's SQL Developer or PL/SQL Developer lacks such behavior and gives correct output.