DatabaseError: ORA-00911: invalid character
Asked Answered
S

1

13

I have following code to execute sql quesry in Oracle db:

try:
    conn = cx_Oracle.connect(DB_LOGIN+"/"+DB_PWD+"@"+SID)
    cursor = connection.cursor()
    cursor.execute(sql)
    connection.commit()
    cursor.close()
    conn.close()
except cx_Oracle.DatabaseError, ex:
    error, = ex.args
    print 'Error.code =', error.code
    print 'Error.message =' , error.message
    print 'Error.offset =', error.offset
    conn.rollback()

I got error: DatabaseError: <cx_Orac...40066758>.

Why I don't see full error message in console? Looks like exception part is not executed. I use python 2.5 and oracle 10.2.0 on linux.

Update: After some investigation I found out that the error is DatabaseError: ORA-00911: invalid character.

My sql string is like: sql = "SELECT ID FROM TABLE WHERE DESC = '" + str(desc[0]) + "';". This is generated string: "SELECT ID FROM TABLE WHERE DESC = '3312';"

When I execute the same request in SQL Developer it works. So what I do wrong?

Skyscraper answered 29/7, 2014 at 14:44 Comment(1)
Remove the trailing semi colon in your query string. The OCI just need your query.. No terminators needed!Fariss
L
36

Delete the semicolon:

sql = "SELECT ID FROM TABLE WHERE DESC  = '" + str(desc[0]) + "'"
Lenka answered 1/10, 2015 at 17:23 Comment(2)
really helpful @LenkaBallista
Basic error, we test with semicolon in SQL editor, happens all the time.Outdoors

© 2022 - 2024 — McMap. All rights reserved.