# Oci adpater and Oracle

**URL:** <https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066>\
**Category:** Ruby\
**Created:** [November 13, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066 "2007-11-13T14:49:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [November 13, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066/1 "2007-11-13T14:49:21Z")

</div>

trying to use ruby (1.8.6) and activerecord(1.15.3) with oci adapter.  
Tried this code :

require ‘active\_record’  
ActiveRecord::Base.establish\_connection(  
:adapter =\> “oci”,  
:username =\> “scott”,  
:password =\> “ross”,  
:host =\> “DCFPROD”)  
class Credit \< ActiveRecord::Base  
set\_table\_name “dc\_dossier”  
set\_primary\_key “n\_dossier”

end  
p Credit.find(:first)

But got this error :  
ORA-00942: table or view does not exist: select \* from (select  
raw\_sql\_.\*, rownum raw\_rnum\_ from (SELECT \* FROM dc\_dossier ) raw\_sql\_  
where rownum \<= 1) where raw\_rnum\_ \> 0 (ActiveRecord::StatementInvalid)

I googled a bit and found that i should try to add that to the Credit  
class :  
connection.execute(‘alter session set current\_schema=DCFPROD’)

Got that :  
OCIError: ORA-01435: user does not exist: alter session set  
current\_schema=DCFPROD (ActiveRecord::StatementInvalid)

I’m clueless. I don’t know much about Oracle.  
Is there someone with an idea ?  
THX.

---

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [November 13, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066/2 "2007-11-13T21:30:34Z")

</div>

Le 13 novembre 2007 à 14:49, Nicolas Couturier a écrit :

> trying to use ruby (1.8.6) and activerecord(1.15.3) with oci adapter.  
> Tried this code :

> ```
> :username => "scott",
> 
> ```
> 
> I googled a bit and found that i should try to add that to the Credit  
> class :  
> connection.execute(‘alter session set current\_schema=DCFPROD’)
> 
> Got that :  
> OCIError: ORA-01435: user does not exist: alter session set

In Oracle speak, each user has his own schema. You should try :

connection.execute(‘alter session set current\_schema=scott’)

(Now, maybe you should create you own user and use that here, as well as  
in the username to connect with.)

Fred

---

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [November 16, 2007, 10:16am UTC](https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066/3 "2007-11-16T10:16:15Z")

</div>

Thanks for your answer.  
But, so far no luck.  
I added that line  
connection.execute(‘alter session set current\_schema=scott’)

Got the first error message :  
ORA-00942: table or view does not exist: select \* from (select  
raw\_sql\_.\*, rownum raw\_rnum\_ from (SELECT \* FROM dc\_dossier ) raw\_sql\_  
where rownum \<= 1) where raw\_rnum\_ \> 0 (ActiveRecord::StatementInvalid)

Tried to add the :database parameter to the connection. No luck.  
Does someone ahve another idea ?

---

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [November 16, 2007, 11:42am UTC](https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066/4 "2007-11-16T11:42:14Z")

</div>

It did the trick.  
The following line :  
connection.execute(‘alter session set current\_schema=scott’)  
was properly set up.  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![kayros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kayros](https://www.ruby-forum.com/u/kayros)\
**Post date:** [November 16, 2007, 10:55am UTC](https://www.ruby-forum.com/t/oci-adpater-and-oracle/120066/5 "2007-11-16T10:55:34Z")

</div>

Le 16 novembre à 10:16, Nicolas Couturier a écrit :

> Got the first error message :  
> ORA-00942: table or view does not exist: select \* from (select  
> raw\_sql\_.\*, rownum raw\_rnum\_ from (SELECT \* FROM dc\_dossier ) raw\_sql\_  
> where rownum \<= 1) where raw\_rnum\_ \> 0 (ActiveRecord::StatementInvalid)
> 
> Tried to add the :database parameter to the connection. No luck.  
> Does someone ahve another idea ?

Well, at first, try to connect to the DB with a query tool (using the  
same password and user than rails, of course), and execute the query as  
given in the logs. Then, if it doesn’t work, try to “decapsulate” it  
step by step :

select \* from (select raw\_sql\_.\*, rownum raw\_rnum\_ from (SELECT \* FROM  
dc\_dossier ) raw\_sql\_ where rownum \<= 1) where raw\_rnum\_ \> 0

select raw\_sql\_.\*, rownum raw\_rnum\_ from (SELECT \* FROM dc\_dossier)

SELECT \* FROM dc\_dossier

It may give you a hint of what’s wrong (especially the precise Oracle  
error).

Fred
