I am getting the error cx_Oracle.DatabaseError: ORA-00933: SQL command not properly ended
when trying to run the following code. I have used
import cx_Oracle
ip = '127.0.0.1'
port = 1234
SID = 'abcd'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
conn = cx_Oracle.connect('username', 'password', dsn_tns)
curs = conn.cursor()
curs.execute('select sysdate from dual;') # Error is here
curs.close()
conn.close()
Running the following works as expected:
conn = cx_Oracle.connect('username', 'password', dsn_tns)
print (conn.version)
conn.close()
To correct this issue, simply go back to the end of the phrase and remove the ORDER BY clause. Be sure to go back to the line prior to the ORDER BY clause and re-insert the statement-ending semi-colon. Another case where the ORA-00933 can occur is when attempting to include an ORDER BY clause with a DELETE statement.
The message ORA-00933: sql command not properly ended. This error is usually caused by an SQL statement with a clause that is not allowed for that statement. Some examples that might cause this error are: An INSERT statement with an ORDER BY clause or an INNER JOIN.
Ending a SQL Command You can end a SQL command in one of three ways: with a semicolon (;) with a slash (/) on a line by itself.
cx_Oracle is a Python extension module that enables querying and updating of Oracle databases using a database API that is common to all database access modules. A number of extensions to the common database API have also been included in order to take advantage of some of the features available exclusively to Oracle.
You don't need the semicolon at the end of the query, maybe it has something to do with that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With