Cursor-loop with DBI

By backend I mean the SQL engine that actually executes your script. All that DBI does is that it passes your command as a string from R to the database engine, and then processes a result (and sometimes not even that - consider dbSendQuery without dbFetch).

Thinking a bit harder about the issue: cursors and variable declarations are not a part of ANSI SQL, but are a part of the various procedural extensions (like PL/SQL in Oracle). It may be that the procedural extensions can not be passed the way of dbExecute statement.

If that is the case - and I am not in a position to check right now - would it be a possibility in your use case to wrap your "cursor code" into a stored procedure and execute as such from R? I am confident that a stored procedure can be called via dbExecute.

1 Like