Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatabaseError: ORA-00911: invalid character

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?

like image 708
khris Avatar asked Jul 29 '14 14:07

khris


1 Answers

Delete the semicolon:

sql = "SELECT ID FROM TABLE WHERE DESC  = '" + str(desc[0]) + "'"
like image 162
Tedezed Avatar answered Oct 24 '22 06:10

Tedezed