菜鸟请教~~急!急!急!

菜鸟请教~~急!急!急!

require 'oci8' #请求OCI8

conn1 = OCI8.new('USERNAME1','PASSWORD1','SERVICE_NAME1') #php?name=%C1%AC%BD%D3" onclick="tagshow(event)" class="t_tag">连接到服务器1

name = conn1.parse("select username from username_table where cd != ' '")
name.exec #执行select语句

while r=name.fetch
puts r #输出username字段
end

conn1.logoff #与服务器1断开连接

conn2 = OCI8.new('USERNAME2','PASSWORD2','SERVICE_NAME2') #连接到服务器2

count = conn2.parse("select count(*) from contactor_table where ownerid in (select id from manager_table where username like '%.....%'))")
count.exec #问题

conn2.logoff #与服务器2断开连接

问题:这里,我想以conn1中查询到的username作为条件进行查询,该如何写呢?因为conn1中返回的结果是username的数组,而在conn2中的select语句又需要作为字符串来查找,'%...%'中不能直接用name.fetch.to_s吧?
while r=name.fetch
count = conn2.parse("select count(*) from contactor_table where ownerid in (select id from manager_table where username like '%#{r}%')")
count.exec
end

使用上面的语句后,可以执行了,但是只能返回第一条记录.然后就开始报错
stmt.c:593:in oci8lib.so: ORA-01001: invalid cursor (OCIError)

请问是为什么呢?
Reason: The error does not occur when testing with one user. In a multiuser environment, if one user (session1) is trying to fetch datasets for a module and *at the same time* if another user (session2) is trying to do the same, for the first user (session1), it is unable to execute the query and results in this error!
是不是并发请求的问题?怎么解决?