0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ruby oci8 で k:v形式のArrayでレコード取得

Last updated at Posted at 2020-11-20

Ruby oci8 で oracle接続して各行のデータをk:v形式のArrayで取り出す話

#!/home/user/local/bin/ruby

require 'oci8'
oracle = OCI8.new('id','pw','service')
oracle.prefetch_rows = 100

result = []
sql = "select * from table_name"

oracle.exec(sql).fetch_hash(){|r| result << r.map{|colname,coldata| "#{colname} : #{coldata}"} }

fetch_hash()っていうふうに()を付けないとだめなのね。
レコードを普通にArrayで取り出したいときはfetch()
oci8は癖があるな。mysql2のほうが扱いやすい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?