any cx_Oracle -skip it

Mike Stenzler mstenzler at ssaris.com
Thu Jul 22 17:04:22 EDT 2004


"Mike Stenzler" <mstenzler at ssaris.com> wrote in message
news:9rULc.45998$DR3.15494 at fe31.usenetserver.com...
> Does anyone have any sample code for the cx_Oracle library?
> www.computronix.com
>
> I have the doco and can connect and do simple ops against my database but
> I'm struggling with
> the correct syntax for implementing bind variables with a cursor.
>


Nevermind...

Some diligent reading of the python DB-API 2.0 yielded the required
knowledge..

import cx_Oracle

## execute wants it's parameters in a dictionary
params = {'val_1':"AA"}

## sql statement uses a bind var style of "named" as default - ":" denotes
bind var
sqlstr = "select name from my.table where id = :val_1"

## open a connection
conn = cx_Oracle.Connection("user/pword at server")

## open a cursor
curs = conn.cursor()

## tell Oracle how many rows to fetch
## at a time - default is 1
curs.arraysize = 256

## send the sql statement to Oracle parser for execution
curs.execute(sqlstr, params)

## fetch resultset from cursor
for name in curs.fetchall():
  print "name: ", name

mike






More information about the Python-list mailing list