# ActiveRecord + Oracle stored procs

**URL:** <https://www.ruby-forum.com/t/activerecord-oracle-stored-procs/113257>\
**Category:** Rails\
**Created:** [August 29, 2007, 10:59am UTC](https://www.ruby-forum.com/t/activerecord-oracle-stored-procs/113257 "2007-08-29T10:59:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [August 29, 2007, 10:59am UTC](https://www.ruby-forum.com/t/activerecord-oracle-stored-procs/113257/1 "2007-08-29T10:59:46Z")

</div>

Guys,

I have googled and googled and cannot find anything on this.

Basically I am using ActiveRecord outside of Rails as part of a test  
suite. I need to call an Oracle stored procedure, and then use  
standard Active Record finders to query the database.

Is there anyway I can call a stored procedure within Active Record? I  
need to be able to pass the procedure parameters and receive  
parameters out, something like

execute( my\_stored\_proc(i\_input, o\_output) );

At the moment I have implemented a solution using the module OCI8,  
which works just fine, but it means I run my stored proc in DB  
connection 1, and query in DB connection 2, so I have to commit 1  
before 2 can see the results, which means I cannot rollback after each  
test!

Can you get access to the OCI8 methods from your Active Record  
connection, or better can I get store proc calls with in and out  
parameters working with standard Active Record functionality?

---

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [August 29, 2007, 1:12pm UTC](https://www.ruby-forum.com/t/activerecord-oracle-stored-procs/113257/2 "2007-08-29T13:12:03Z")

</div>

On Aug 29, 9:59 am, stephen O’D [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> parameters out, something like  
> connection, or better can I get store proc calls with in and out  
> parameters working with standard Active Record functionality?

After another batch of googling, I have concluded you just cannot do  
what I want out of the box, but its easily added. I documented what I  
did at

> **[ActiveRecord, Oracle and stored procedures](https://sodonnell.wordpress.com/2007/08/29/activerecord-oracle-and-stored-procedures/)**
>
> After much painful searching for a built in way to get ActiveRecord to execute a stored procedure on Oracle complete with in and out bind variables I have concluded that its just not possible. The …

Basically I had to add a new method to  
ActiveRecord::ConnectionAdapters::OracleAdapter that directly call the  
OCI8#exec method and it seems to do what I want.
