# Ruby-oci8 question

**URL:** <https://www.ruby-forum.com/t/ruby-oci8-question/175541>\
**Category:** Ruby\
**Created:** [September 15, 2009, 12:16pm UTC](https://www.ruby-forum.com/t/ruby-oci8-question/175541 "2009-09-15T12:16:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [September 15, 2009, 12:16pm UTC](https://www.ruby-forum.com/t/ruby-oci8-question/175541/1 "2009-09-15T12:16:17Z")

</div>

Hi,

I have some problem, i want to make select query with $name variable but  
i cant, this is my code please help what is wrong

print “Enter name :”  
$name = STDIN.gets

conn = OCI8.new(‘user’, ‘pass’)  
num\_rows = conn.exec(“SELECT \* FROM test where name like '%” + $name +  
“%’”)  
do |r|  
puts r.join(’,’)  
end

---

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [September 15, 2009, 12:29pm UTC](https://www.ruby-forum.com/t/ruby-oci8-question/175541/2 "2009-09-15T12:29:53Z")

</div>

On Sep 15, 2009, at 1:16 PM, beny 18241 wrote:

> Hi,
> 
> I have some problem, i want to make select query with $name variable  
> but  
> i cant, this is my code please help what is wrong
> 
> print “Enter name :”  
> $name = STDIN.gets

this $name has a ‘\n’ in it, try STDIN.gets.chomp

---

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [September 15, 2009, 12:53pm UTC](https://www.ruby-forum.com/t/ruby-oci8-question/175541/3 "2009-09-15T12:53:20Z")

</div>

On Sep 15, 2009, at 1:33 PM, beny 18241 wrote:

> > > print “Enter name :”  
> > > $name = STDIN.gets
> > 
> > this $name has a ‘\n’ in it, try STDIN.gets.chomp
> 
> thanks works

You’re welcome. Also consider removing the ‘$’ and using the variable  
as just “name” just like conn and num\_rows (I’m guessing you’re from a  
perl or php background).

---

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [September 15, 2009, 12:33pm UTC](https://www.ruby-forum.com/t/ruby-oci8-question/175541/4 "2009-09-15T12:33:28Z")

</div>

Patrick O. wrote:

> On Sep 15, 2009, at 1:16 PM, beny 18241 wrote:
> 
> > Hi,
> > 
> > I have some problem, i want to make select query with $name variable  
> > but  
> > i cant, this is my code please help what is wrong
> > 
> > print “Enter name :”  
> > $name = STDIN.gets
> 
> this $name has a ‘\n’ in it, try STDIN.gets.chomp

thanks works
