How can I get the output of a sql script using Ruby Active Record?

Notes: Using Ruby 2.4, oci8 / oracle enhanced adapter.

I was using sqlplus to execute some DDL / DML I have. Basically this:

system "echo / | sqlplus  #{db.username}/\"#{db.password}\"@#{}:#{db.port}/#{db.sid} @\"#{file_to_execute}\" > #{@SQLOUT_LOG}"

I want to move away from using sqlplus and use active record instead. So I got this working:


And that does basically the same thing, except: I cannot access the 'script output' that I got from SQLplus (or even SQLDeveloper). This 'execute' function returns table rows, which I usually don't care about or need.

I just want a string of the output result of the script after I run it. Example:

Procedure MYPROCEDURE compiled

3 rows inserted.


1 answer

  • answered 2018-01-16 23:36 Josh Brody

    puts ActiveRecord::Base.connection.execute("#{file_path}"))