9

I'm new to Python, using cx_Oracle.execute to insert a row into a table.

I prepare the insert statement, which works on SQL developer.

print statements prior to the execute indicate it hangs on execute. A simple select statement works using the same package.

  • Python version is 2.7
  • Oracle version is 11g
  • cx_Oracle version is 5.2.1
  • Eclipse is 4.4.2
  • Pydev is 4.5.5

I have tried this on Anaconda as well, same result.

import cx_Oracle

Connection = cx_Oracle.connect('connectioninfo')
cursor = connection.cursor()
print(cx_Oracle.__file__) 
print(cx_Oracle._version)

sql1 = "insert into date_dim(dateid) values (20170523)"
print(sql1)
cursor.execute(sql1) # hangs here 
count = cursor.rowcount 

print(count)
connection.commit() # Never gets to this statement        
cursor.close()
connection.close()

1 Answer 1

14

It looks like I had another session open on Sql Developer to test the insert script where I never run a Commit so when I run the Python insert script, somehow it was hanging waiting for the other commit to be issued so it can issue its own commit which was the next line in the code but the other commit was never issued in Sql Developer! As soon as I run a commit in Sql Developer, Python completed the insert. What do you know? Posted my first question on Stackoverflow and my first answer to my first question, that's gotta be a first!

Sign up to request clarification or add additional context in comments.

2 Comments

This is fantastic. I did the same mistake and was stuck to it for half a day. Very useful post.
Me too. This post is really helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.