[DB-SIG] Example python x oracle

Bob Kimble rjkimble at gmail.com
Thu Jun 12 02:56:10 CEST 2008


Here's a sample script (cut between the lines):
-------------------------------------------------------------------
#!/usr/bin/env python

import cx_Oracle

# Establish a connection:
connection = cx_Oracle.connect('user/password at database')

# Create a cursor object:
cursor = connection.cursor()

# Run your query:
cursor.execute('''select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') now from
dual''')

# Get the column names:
cols = tuple([x[0].lower() for x in cursor.description])

# Fetch the results:
rs = cursor.fetchall()

# Turn them into rows:
rows = [dict(zip(cols, r)) for r in rs]

# Loop through the rows and print out the results:
for row in rows:
    print 'According to Oracle, the time now is:', row['now']

# That's it!
-------------------------------------------------------------------

Replace user/password at database with the string you would use to connect to
Oracle with SQL*Plus, and that should do it.

Good luck!

Regards,

.... Bob

2008/6/11 Marcel Rosa <marcelr_br at yahoo.com.br>:

> I am Oracle DBA and would like to use a python to developer some intranet
> report,
>
> do you have same examples?
>
>
>
> thanks.
>
> ------------------------------
> Abra sua conta no Yahoo! Mail<http://br.rd.yahoo.com/mail/taglines/mail/*http://br.mail.yahoo.com/>,
> o único sem limite de espaço para armazenamento!
>
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20080611/fff06fd3/attachment.htm>


More information about the DB-SIG mailing list