1

I am on Oracle-12c with Python-3 and cx-oracle.

How to handle the below query of "No rows returned" for the SQL? If no rows returned I would like the string "Inactive" assigned to the result.

cursor.execute("select STATUS from DOMAINTABLE")
for result in cursor:
 print(result[0])
 row = result.fetchone()
 if row == None:
 break
 print ("Inactive")
James Z
12.3k10 gold badges27 silver badges49 bronze badges
asked Apr 10, 2020 at 18:21

1 Answer 1

1

You should either iterate over the cursor or call the fetchone method but not do both:

cursor.execute("select STATUS from DOMAINTABLE")
for status, in cursor:
 print(status)
 break
else:
 print('Inactive')

or:

cursor.execute("select STATUS from DOMAINTABLE")
row = result.fetchone()
if row is None:
 print('Inactive')
else:
 print(row[0])
answered Apr 10, 2020 at 18:43
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.