0

I'd like to select a next id from a sequence in oracle using oci8 and ruby. What's the easist way of doing so? Example wrong code:

id = @conn.exec( 'Select NEXT_ID.NEXTVAL from dual' )

.exec returns a cursor. Is there an easy way of just getting the one value I need from the exec or similar method?

Martlark
  • 14,208
  • 13
  • 83
  • 99

1 Answers1

1
@conn.exec('Select NEXT_ID.NEXTVAL from dual') {|row| id = row[0]}

You can also do

id = @conn.exec('Select NEXT_ID.NEXTVAL from dual').fetch[0]
Martlark
  • 14,208
  • 13
  • 83
  • 99
saihgala
  • 5,724
  • 3
  • 34
  • 31