Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

No Output while executing sqlplus query in Python

1018127Oct 3 2013 — edited Oct 8 2013

Hi All,

I have below script which runs ok without any errors but does not give me any output.

My task is to be able to run a sql query from python script and then use the result to prepare a xml file.

As the first step I am trying to build Python to extract query data for me, but below script not giving any output even when I have ~40 rows in table.

I would like to connect to Sqlplus through cx_Oracle library.

import cx_Oracle
  
import sys try:

  
# First, create a DB connection:
connection
= cx_Oracle.Connection('UserName' + '/' + 'password' + '@' + 'DatabaseName')

# Next, obtain a cursor:
cursor
= connection.cursor()

# Now we can execute SQL code via our cursor:
cursor
.execute('select * from table')

# And fetch query results one by one:
for i in range(cursor.rowcount):
row
= cursor.fetchone()
print row[1]
cursor
.close()

except
cx_Oracle
.DatabaseError, exc: print >> sys.stderr, "Oracle-Error:", str(exc
)



Please help me to find what is wrong in this script?

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2013
Added on Oct 3 2013
4 comments
5,358 views