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
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
blhsing
109k9 gold badges89 silver badges132 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py