Loading data from a stored procedure

I'm trying to load data from Oracle into my index.
I need to use a stored procedure, which uses a cursor to iterate over data.
My SQL cript begins with a declaration section, in which I declare the cursor and the temporary variable. The error I receive is
[2019-10-08T17:14:00,698][WARN ][logstash.inputs.jdbc ] Exception when executing JDBC query {:exception=>#<Sequel::DatabaseError: Java::JavaSql::SQLException: SQL string is not Query>} [2019-10-08T17:15:00,753][ERROR][logstash.inputs.jdbc ] Java::JavaSql::SQLException: SQL string is not Query: DECLARE

I tried also with a script without the declare section, but I receive the same error. My question is: is it possible to do what I'm trying to do?