This is a follow-up from this question.
Functions are not allowed to write to the database, but what if I wanted to update a record every time a function was called, specifically a recursive function?
Currently, I have a function that takes an ID and returns a float. I'd like to update a table using the given ID and the returned float. Ordinarily, a simple stored procedure could be used to call the function and then make the update. My function is recursive, and so the solution isn't that simple...
I'm thinking about attempting to do this:
- Create the recursive function so that it takes a table as a parameter
- If the table is null, create it; else, copy the table to a new variable (because it will be readonly)
- update the copied table in the function before making the recursive call, and pass the copy to the function
- at the end, return the complete table (not sure how I will "know" is it complete yet)
- call this function from a stored procedure that uses the returned table to make several updates
I'm looking for alternatives before I even try something like that. Seems that this has been done before.