Glenville Pecor
Glenville Pecor

Reputation: 147

cx_Oracle ORA-00933 SQL command not properly ended

I am trying to run a statement with cx_Oracle and I keep getting the issue where it says that the SQL Command not properly ended but after reading documentation It seems that this is correct, but in reality it is incorrect. cx_Oracle.DatabaseError: ORA-00933 SQL command not properly ended

vary = "'Y'"
dsn_tns = cx_Oracle.makedsn(hostName, port,
                            service_name=serviceName) 
conn = cx_Oracle.connect(user=usr, password=__pswrd,
                         dsn=dsn_tns) 

c = conn.cursor()  

tempCheck = "'%{0}/%'".format(checkerAR)
statmentApp = 'SELECT TITLE,APP_URL from SOME.DATABASE' \
              'WHERE UPPER(APP_URL) LIKE UPPER(:tc)' \
              'AND ACTIVE_FLAG = :y'
c.execute(statmentApp,tc = tempCheck , y = vary)

At the c.execute line is where the error gets flagged. I am trying to enter in tempCheck into the statement because I want to add wildcards to the SQL statement. What am I doing wrong here?

Upvotes: 0

Views: 997

Answers (1)

Christopher Jones
Christopher Jones

Reputation: 10496

print (statmentApp)

gives:

SELECT TITLE,APP_URL from SOME.DATABASEWHERE UPPER(APP_URL) LIKE UPPER(:tc)AND ACTIVE_FLAG = :y

showing that the string concatenation worked too well. To retain necessary whitespace you'll find it easier to use triple quotes:

statmentApp = """SELECT TITLE,APP_URL from SOME.DATABASE
                 WHERE UPPER(APP_URL) LIKE UPPER(:tc)
                 AND ACTIVE_FLAG = :y"""

Upvotes: 1

Related Questions