Skip to content
Advertisement

SQL command not properly ended in Python OracleSQL

I’m having some trouble with SQL code that works when I run it in DBeaver, but when I execute it with cx_Oracle it comes up with the error of:

The python code is good, but I’m not much of a SQL programmer, so maybe someone can look to see if there is any obvious coding errors. It’s just weird that the code works in DBeaver but not with cx_Oracle.

Here is the code:

Advertisement

Answer

Query itself looks OK (as you said, it works in DBeaver). Maybe it is that Python doesn’t “like” closing statement terminator (semi-colon at the very end of the query) – try to remove it.


Apart from that, I’d suggest you not to rely on Oracle’s guessing date format. Instead of TO_DATE ('26-JUL-2021'), use TO_DATE ('26-JUL-2021', 'DD-MON-YYYY') (i.e. always provide appropriate format mask). Note that MON can be tricky if database doesn’t speak English (for example, it would fail in my database which speaks Croatian) so – it is safer to use e.g. TO_DATE ('26.07.2021', 'DD.MM.YYYY')

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement