Skip to content
This repository

Run single sql statements against an Oracle schema

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 oci8_simple.gemspec


This gem is a thin wrapper around the ruby-oci8 gem. The client is intended to be used by simple scripts to aid automation. The code is intentionally light-weight and featureless, with very little startup time. It is not meant to be a Ruby ORM for Oracle - if you want that, look at the OracleEnhancedAdapter.

This gem installs a few command-line scripts:

  • oci8_simple

    • a command to run arbitrary SQL

  • describe

    • a command to describe a table

  • show

    • a command to list things in the database (tables, views, etc.)

You can also use oci8_simple in your Ruby scripts by creating an instance of Oci8Simple::Client (see more below).



gem install oci8_simple


Oci8Simple will look in three places for your database configuration, in the following order:

  • Dir.pwd + database.yml

  • Dir.pwd + config/database.yml

  • ~/.oci8_simple/database.yml

The database.yml format is compatible with the Rails format.

  database: oracle.hostname:1521/sid
  username: foo_dev
  password: OMG333
  database: oracle.hostname:1521/sid
  username: foo_test
  password: OMG333


All logging is done to ~/.oci8_simple/oci8_simple.log.

Command-Line Examples


This script allows you to run single statements against an arbitrary Oracle schema via the command line.

Run a query against development schema
  oci8_simple "select id, name from flavors" 

Run a query against a different schema
  oci8_simple "select id, name from flavors" int

  oci8_simple --help


This script shows a description of a table, including the column names (sorted), the type and size for each column, the nullable status of the column, and the default value, if any.

Show column information for a table named "holidays"
  describe holidays

  describe --help


This command can list the following items in the database: functions, packages, procedures, sequences, synonyms, tables, types, and views.

Show a list of all tables in the database
  show tables

Show a list of all views in the database
  show views

  show --help

Code Examples

  • Initialize a client against the development schema

    require 'rubygems'
    require 'oci8_simple'
    client =
  • Run a simple select query against development schema'select id, name from foos')                => [[2, "lol"], [3, "hey"], ...]'select id, name from foos', :hash => true) => [{:id => 2, :name => "lol"}, {:id => 3, :name=>"hey"}, ...])
  • Update something <<-SQL
      UPDATE foos SET bar='baz' WHERE id=1233
  • Run some DDL <<-SQL
      CREATE TABLE foos (
         ID NUMBER(38) NOT NULL
  • Run some PL/SQL <<-SQL
        a NUMBER;
        b NUMBER;
        SELECT e,f INTO a,b FROM T1 WHERE e>1;
        INSERT INTO T1 VALUES(b,a);
  • Run a query against stage schema"stage").run('select id, name from foos') => [[2, "lol"], [3, "hey"], ...]

Contributing to oci8_simple

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2011 Billy Reisinger. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.