PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 6, 2022

[FIXED] How to execute a scalar query with oci8 and ruby

 December 06, 2022     oci8, ruby, sql     No comments   

Issue

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?


Solution

@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]


Answered By - saihgala
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing