Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Wednesday, November 27, 2019

Connecting Oracle with Python via cx_Oracle extension


Installation Prerequisites

  • Python 2.7, 3.5 or above
  • Oracle Client / Oracle Instant Client "Basic" or "Basic Light"
  • libaio / libaio1 package


Installation Reference



Sample Python Code

import cx_Oracle

# Make DSN address. Real values for host address, port and service name were replaced by '<>'.

dsn = cx_Oracle.makedsn('<host_address>', '<port>', service_name='<service_name>')

# Connect to DSN

orcl = cx_Oracle.connect(user='<username>', password='<password>', dsn=dsn)

# Get cursor

cursor = orcl.cursor()

# Execute SQL statement

cursor.execute('<SQL SELECT STATEMENT>')

# Fetch result

data = cursor.fetchone()

Tuesday, January 10, 2012

Column aggregation in Oracle

Suppose we have a table (TBL) in Oracle with columns (CATEGORY, ATTR). Consider the following:

CATEGORYATTR
1A
1B
1C
2D
2E
2F
3X
3Y
3Z

We want to convert the table as follows:

CATEGORYATTR
1A,B,C
2D,E,F
3X,Y,Z

This can be done via the SQL below:

select CATEGORY, 
       xmlagg(xmlelement(c, ATTR || ',')).extract('//text()') 
from TBL 
group by CATEGORY

CSP on Apache

To add CSP to root if sort of funny. The following will NOT work for most cases !!     <LocationMatch "^/$">        Header s...