#fetch.rb: Fetch data from database
require 'config.rb'
# Create a connection to Oracle
conn = OCI8.new(DB_USER, DB_PASSWORD, DB_SERVER)
# parse and exec the statement
cursor = conn.parse("select * from regions")
cursor.exec
# output column names
puts cursor.getColNames.join(",")
# output rows
while r = cursor.fetch
puts r.join(",")
end
# close the cursor and logoff
cursor.close
conn.logoff
puts '-'*80
|