简体   繁体   English

如何使用oci8和ruby执行标量查询

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

I'd like to select a next id from a sequence in oracle using oci8 and ruby. 我想使用oci8和ruby从oracle中的序列中选择下一个id。 What's the easist way of doing so? 这样做的简便方法是什么? Example wrong code: 错误代码示例:

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

.exec returns a cursor. .exec返回一个游标。 Is there an easy way of just getting the one value I need from the exec or similar method? 是否有一种简单的方法可以从exec或类似方法中获取我需要的一个值?

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

你也可以

id = @conn.exec('Select NEXT_ID.NEXTVAL from dual').fetch[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM