This is not an answer to the OP question (but it is a “proof of concept” to show how something like what it does in PL / SQL can be done in plain SQL). I use only the response format, because what I will do below does not fit into the comment.
OP asked to see how summing an infinite series to the right degree of accuracy can be done in pure SQL. I will give two examples.
First example :
Infinite series with positive terms: e = sum [ j = 0 to infinity ] ( 1 / factorial strong> (j) ) . The trivial upper bound of the error for the sum from 0 to n is the last term added to the row. The recursive query below (which requires Oracle 11.1 or higher - actually 11.2, as I wrote it, with the column names in the declaration, but it is easy to change it for 11.1) calculates the e value accurate to 38 decimal places (the maximum precision available in Oracle). The inverse factorial series for e converges very quickly; it takes only 35 steps and works in less than 0.001 seconds on my old home computer (which is just a big Dell tablet with a keyboard).
Edit : Doo! Only I can write something where e = 3.71828! Despite the fact that in the recursive query I add ALL terms (including 1/0!), I started the sum with 1 instead of 0. (Fixed now, but had this error before the correction.)
with rec ( j, s, next_term, err ) as ( select 0, 0, 1, 2 from dual union all select j+1, s + next_term, next_term/(j+1), next_term from rec where err > power(10, -38) and j < 1000000000 ) select max(j) as steps, round(max(s), 38) as e from rec ; STEPS E
Second example :
OK, so now we take an alternating series (where the absolute value of the last term is always the upper limit of the error), and let it take a very slow approach:
ln ( 2 ) = sum [ j = 1 to infinity ] ( strong> (-1) ^ (j - 1) / j )
The query below computes ln (2), accurate to five decimal places; here we know in advance that we need 100,000 steps, and the calculations on my machine took about 1.1 seconds. (Remember, this is a very slowly converging series.)
with rec ( j, s, sgn ) as ( select 0, 0, 1 from dual union all select j+1, s + sgn / (j+1), -sgn from rec where j <= 100000 ) select 100000 as steps, round(s, 5) as ln_2 from rec where j = 100000 ; STEPS LN_2