Select to view content in your preferred language

cx_Oracle error "SQL Statement not properly ended

887
3
Jump to solution
04-30-2022 01:58 PM
JoshuaBaker2
New Contributor

Hello all, I am currently doing an assignment that links python to SQL Developer, and I keep getting errors that my statements for "custCursor.execute" and "delivCursor.execute" are not properly ended, but I cannot figure out why. any help would be greatly appreciated, and the code is posted below. the first query "custIDCursor.execute" works great, and will even display everything that I need it to. 

 

#Get Parameter for the CustIDQuery
prompt1 = '>'
print(f"Enter the Customer's Last Name: ")
lnameValue = input(prompt1)

# Set up cursor and retrieve data (Created by Joshua W. Baker)
custIDCursor = conn.cursor()
custIDCursor.execute("SELECT c.custno FROM customer c WHERE c.lname = '%s'" % lnameValue)
custIDValue = custIDCursor.fetchall()
print(custIDValue)

custCursor = conn.cursor()
custCursor.execute("SELECT c.fname, c.lname, c.city FROM customer c WHERE c.custno = '%s' " % custIDValue)

delivCursor = conn.cursor()
delivCursor.execute("SELECT b.bagno, b.deliverydatetime, b.runno FROM bag b WHERE b.custno = '%s' " % custIDValue)

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

What happens when you add

custValue = custCursor.fetchall() 

and

delivValue = delivCursor.fetchall()

under your two statements that are erroring?  It looks like you are setting them up but not executing them and since you are using the same conn without garbage collecting, the previous is staying open.

You may also trying to set them up in with statements so they are garbage collected and resources released before the next cursor is created using the same conn.

with conn.cursor() as custCursor:
    custCursor.execute(f"SELECT c.fname, c.lname, c.city FROM customer c WHERE c.custno = '{custIDValue}'")
    custValue = custCursor.fetchall()

 

View solution in original post

0 Kudos
3 Replies
by Anonymous User
Not applicable

What happens when you add

custValue = custCursor.fetchall() 

and

delivValue = delivCursor.fetchall()

under your two statements that are erroring?  It looks like you are setting them up but not executing them and since you are using the same conn without garbage collecting, the previous is staying open.

You may also trying to set them up in with statements so they are garbage collected and resources released before the next cursor is created using the same conn.

with conn.cursor() as custCursor:
    custCursor.execute(f"SELECT c.fname, c.lname, c.city FROM customer c WHERE c.custno = '{custIDValue}'")
    custValue = custCursor.fetchall()

 

0 Kudos
JoshuaBaker2
New Contributor

This is exactly what needed to be done, thanks so much for your help! I’m new to SQL so combining it with python was a struggle for me.

0 Kudos
by Anonymous User
Not applicable

Does the .execute() string need to be terminated with a semicolon?

0 Kudos