Skip to main content

Oracle

Oracle Database is an enterprise relational database engine. In Gredit, this integration allows connecting to an Oracle instance via ODBC.

What it is used for

Configure an Oracle connection so that scripts can execute SQL queries and read or write data in a relational database.

Configuration

Required data

FieldDescription
ServernameConnection string in the format /domain:port/database. Example: /example.dominio.com:1521/ex
userIDDatabase user
PasswordUser password

Adding the database in Gredit

  1. Go to the Databases section and create a new configuration.
  2. Fill in Servername, userID, and Password.
  3. In Driver, use OracleODBC.
  4. The Name value will be the identifier used to inject the connection into scripts.

Add the database in Gredit

Usage in scripts

Ruby

require 'json'
require 'odbc_utf8'
require 'ostruct'

client = ODBC.connect 'OracleTest'
columns = %w(name email)
results = []

query = <<-SQL
SELECT #{columns.join ','} FROM users;
SQL

stat = client.prepare query

stat.execute

stat.each_hash do |row|
results << row
end

stat.drop

puts JSON.generate results

Python

Add the pyodbc library under Libraries in the script settings.

Libraries

import pyodbc

cnxn = gredit.connect('OracleTest')
cursor = cnxn.cursor()
cursor.execute("SELECT name, email FROM users WHERE ROWNUM <= 10")

columns = [col[0].strip().lower() for col in cursor.description]
rows = cursor.fetchall()

for r in rows:
h = dict(zip(columns, r))
print(h["name"], h["email"])

cursor.close()
cnxn.close()

Relationship with other modules

  • Accounts: The Oracle connection belongs to an account.
  • Scripts: Can be associated with one or more scripts optionally.
  • Permissions: Controlled by assigned roles and permissions.