# Call an Oracle function

**URL:** <https://www.ruby-forum.com/t/call-an-oracle-function/177977>\
**Category:** Rails\
**Created:** [October 27, 2009, 1:10pm UTC](https://www.ruby-forum.com/t/call-an-oracle-function/177977 "2009-10-27T13:10:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 27, 2009, 1:10pm UTC](https://www.ruby-forum.com/t/call-an-oracle-function/177977/1 "2009-10-27T13:10:11Z")

</div>

Hi all,  
I need to call a Oracle function from Rais.Does anyone have some  
experience with it?

Thanks,  
Rafael

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [October 27, 2009, 2:53pm UTC](https://www.ruby-forum.com/t/call-an-oracle-function/177977/2 "2009-10-27T14:53:04Z")

</div>

If you just want to call a function you could do something like

results = ActiveRecord::Base.connection.select\_all “select my\_function  
(‘some argument’) value from dual”  
puts results.first[‘value’]

For example

> > ActiveRecord::Base.connection.select\_all “select 7+5 value from dual”  
> > =\> [{“value”=\>12}]

If you have a more complicated plsql stored procedure that maybe sets  
more than one result parameter you can use the plsql gem  
[GitHub - rsim/ruby-plsql: ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures. It could be used both for accessing Oracle PL/SQL API procedures in legacy applications as well as it could be used to create PL/SQL unit tests using Ruby testing libraries.](http://github.com/rsim/ruby-plsql). This gem lets you call arbitrary  
plsql procedures with any input or output parameters.

Hope this helps  
–Alex

On Oct 27, 8:10 am, Rafael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
