Skip to content

Instantly share code, notes, and snippets.

@daicham
Created November 19, 2012 08:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daicham/4109527 to your computer and use it in GitHub Desktop.
Save daicham/4109527 to your computer and use it in GitHub Desktop.
A sample ruby code of executing SQL for Oracle
# encoding: utf-8
#
# Prerequisite:
# gem install ruby-oci8
require 'oci8'
def log(message)
puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} #{message}"
end
log "connecting..."
conn = OCI8.new("hoge", "hoge_passwd", "//localhost/db")
log "connected."
begin
num = conn.exec("insert into ...")
conn.commit
log "#{num} inserted."
ensure
log 'logging off...'
conn.logoff
log 'logged off.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment