# Convert OCI8 SQL Results to JSON

**URL:** <https://discourse.sensu.io/t/convert-oci8-sql-results-to-json/824>\
**Category:** Sensu Classic (EOL)\
**Created:** [June 15, 2017, 3:30am UTC](https://discourse.sensu.io/t/convert-oci8-sql-results-to-json/824 "2017-06-15T03:30:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Russy\_Alfafara](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@Peter\_Russy\_Alfafara](https://discourse.sensu.io/u/Peter_Russy_Alfafara)\
**Post date:** [June 15, 2017, 3:30am UTC](https://discourse.sensu.io/t/convert-oci8-sql-results-to-json/824/1 "2017-06-15T03:30:11Z")

</div>

Hi Experts,

I would like to seek your assistance on how to convert my SQL results to JSON. Below is my .rb code and the results I want to convert

#! /usr/bin/env ruby

require ‘oci8’

require ‘json’

#Create a connection to the Oracle Database

oci = OCI8.new(‘GLOGOWNER’,‘Sh#reit1’,‘192.168.30.223:1521/orcl’)

#parse and exec the statement

cursor = oci.parse(‘select shipment\_gid,total\_actual\_cost, total\_actual\_cost\_base, start\_time from shipment where rownum \<= 3’)

cursor.exec

#output column names

#puts cursor.getColNames.join(",")

#output rows

#while r = cursor.fetch

# puts r.join(",")

#end

hashes = cursor.collect { |ro|

ro.to\_json

}

JSON.generate(hashes)

#close the cursor

cursor.close

oci.logoff

puts ‘-’\*80

``

Warning: NLS\_LANG is not set. fallback to US7ASCII. SHIPMENT\_GID,TOTAL\_ACTUAL\_COST,TOTAL\_ACTUAL\_COST\_BASE,START\_TIME DEMO.01064,0.3e4,0.29570999999999999090505298227071762085e4,2016-05-02 09:00:00 +0000 GSK.01136,0.0,0.0,2016-05-22 09:18:00 +0000 DEMO.01066,0.2e4,0.19714000000000000909494701772928237915e4,2016-05-02 13:10:00 +0000

``

Unfortunately I get the error below

Warning: NLS\_LANG is not set. fallback to US7ASCII. /opt/sensu/embedded/bin/dbconnect.rb:19:in `<main>': undefined method`collect’ for #OCI8::Cursor:0x000000007e8d80 (NoMethodError)

``

Any ideas on how to do the conversion properly?

Regards,

Peter

---

<div class="post-metadata">

**Author:** ![jspaleta](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/jspaleta/32/141_2.png) [@jspaleta](https://discourse.sensu.io/u/jspaleta)\
**Post date:** [November 22, 2018, 2:07am UTC](https://discourse.sensu.io/t/convert-oci8-sql-results-to-json/824/2 "2018-11-22T02:07:56Z")

</div>


