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")

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])
Sign up to request clarification or add additional context in comments.

Comments

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.