I want to loop over a set of rows and call user defined function to perform some operation on it
Say I have a table below, with hash value stored in the hash column of the table
Desc temp
————————————
id Number
name Varchar
hash VarBinary
Now I have a user defined function usr_fun which takes two hash values, first row hash value and next row hash value and performs some operation on them and then returns the new hash value as the result. Now it should use this result and pickup the third row hash value and execute the same funtion and continue like this for all the rows and finally return the result.
Select usr_fun(row.hash,nextrow.hash) as result from temp
Result
—————
XXXXXXXX
Same problem visually
select * from Temp
—————
Hash
—————
1
2
3
4
Select usr_fun(row.hash,nextrow.hash) as result from temp
(1+2=3, 3+3=6, 6+4=10)
Result
—————
10
Thanks