# ActiveRecord and Oracle Views

**URL:** <https://www.ruby-forum.com/t/activerecord-and-oracle-views/72785>\
**Category:** Rails\
**Created:** [October 19, 2006, 12:27am UTC](https://www.ruby-forum.com/t/activerecord-and-oracle-views/72785 "2006-10-19T00:27:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [October 19, 2006, 12:27am UTC](https://www.ruby-forum.com/t/activerecord-and-oracle-views/72785/1 "2006-10-19T00:27:42Z")

</div>

Hi all, so I’m developing an app in Rails (first time, have been using  
Ruby a while), and I’m running into an issue with ActiveRecord. It  
doesn’t seem to like Oracle views.

We have a large application where most stuff happens in Oracle stored  
procedures. But, for displaying and joining this data I was hoping to  
use ActiveRecord and Rails. When I try to simply say:

class Environment \< ActiveRecord::Base  
end

I get:

```
ORA-24372: invalid object for describe

```

I assume ActiveRecord is doing “describe environments” magic to create  
accessors/etc. (Note: I get this same error trying this from sqlplus as  
you can’t describe views)

Has anyone tried this and/or had success/failure? I’d like to be able  
to use views with Rails (and ActiveRecord is not a requirement; just  
trying to understand everything).

Thanks,  
Nate

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [October 19, 2006, 6:41am UTC](https://www.ruby-forum.com/t/activerecord-and-oracle-views/72785/2 "2006-10-19T06:41:46Z")

</div>

Nate,

> I assume ActiveRecord is doing “describe environments” magic to create  
> accessors/etc. (Note: I get this same error trying this from sqlplus as  
> you can’t describe views)

It may not be using the describe function. For example I can use  
sqlplus to  
describe a view that I created called venvironments. I don’t have  
ActiveRecord  
setup so I didn’t test that part. But Oracle describe seemed to work on  
a view.

Matt

Listing:

> sqlplus blah/blah@blah  
> Connected to:  
> Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production  
> With the Partitioning, OLAP and Oracle Data Mining options  
> JServer Release 9.2.0.6.0 - Production

SQL\> select object\_name,object\_type  
2 from all\_objects  
3 where object\_name = ‘VENVIRONMENTS’;

OBJECT\_NAME OBJECT\_TYPE

* * *

VENVIRONMENTS VIEW

SQL\> desc venvironments  
Name Null? Type

* * *

* * *

ID NOT NULL NUMBER(38)  
ENVIRONMENT NOT NULL VARCHAR2(64)  
LAYOUT\_ID NOT NULL NUMBER(38)  
LAYOUT VARCHAR2(32)  
ENVIRONMENT\_TYPE\_ID NOT NULL NUMBER(38)  
ENVIRONMENT\_TYPE VARCHAR2(32)  
LIFE\_CYCLE\_ID NOT NULL NUMBER(38)  
LIFE\_CYCLE VARCHAR2(32)  
DEFAULT\_DBSERVER\_ID NUMBER(38)  
DEFAULT\_DBSERVER VARCHAR2(32)  
AUTH\_OBJECT\_ID NOT NULL NUMBER(38)  
AUTH\_OBJECT VARCHAR2(64)  
UPDATE\_USER VARCHAR2(64)  
UPDATE\_DATE DATE  
CREATE\_USER VARCHAR2(64)  
CREATE\_DATE DATE

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [October 19, 2006, 7:19am UTC](https://www.ruby-forum.com/t/activerecord-and-oracle-views/72785/3 "2006-10-19T07:19:49Z")

</div>

In the code of oracle connection adaptor for active record it looks  
like views are intended to be supported. See the “when OCI\_PTYPE\_TABLE,  
OCI\_PTYPE\_VIEW” line.

--------- excerpt -----------  
# Uses the describeAny OCI call to find the target owner and  
table\_name  
# indicated by +name+, parsing through synonynms as necessary.  
Returns  
# an array of [owner, table\_name].  
def describe(name)  
@desc ||= @@env.alloc(OCIDescribe)  
@desc.attrSet(OCI\_ATTR\_DESC\_PUBLIC, -1) if VERSION \>= ‘0.1.14’  
@desc.describeAny(@svc, name.to\_s, OCI\_PTYPE\_UNK)  
info = @desc.attrGet(OCI\_ATTR\_PARAM)

```
  case info.attrGet(OCI_ATTR_PTYPE)
  when OCI_PTYPE_TABLE, OCI_PTYPE_VIEW
    owner = info.attrGet(OCI_ATTR_OBJ_SCHEMA)
    table_name = info.attrGet(OCI_ATTR_OBJ_NAME)
    [owner, table_name]
  when OCI_PTYPE_SYN
    schema = info.attrGet(OCI_ATTR_SCHEMA_NAME)
    name = info.attrGet(OCI_ATTR_NAME)
    describe(schema + '.' + name)
  end
end

```

* * *

Source File:  
[http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active\_record/connection\_adapters/oracle\_adapter.rb](http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb)

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [October 19, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/activerecord-and-oracle-views/72785/4 "2006-10-19T23:17:41Z")

</div>

Just so everyone knows the resolution, it turned out my view had become  
invalid because an underlying table had issues. The Oracle error was  
just confusing. I managed to get the _real_ error by doing a “select \*  
from environments”. Once I corrected the view it works.
