digmapper

SQL Statement in Python

Discussion created by digmapper on Feb 5, 2014
Latest reply on Feb 6, 2014 by digmapper
I am getting one of 2 errors and I don't know why. They are ORA-00911: invalid character and ORA-00933: (something about the statement not ended correctly). I am hoping a fresh set of eyes can help with it. Here is the code:

        orcl = cx_Oracle.connect("xxx/xxx@xxx")
        curs = orcl.cursor()
        database = "Database Connections\\xxx.sde\\xxx.xxx_xxx"
        sql1 = "create view RSIDs as " 
        sql2 = "select * " 
        sql3 = "from "+database+" where "
        sql4 = "xxxx like '%RSID%' or xxxxx like '%m%'"
        sql = str(sql1+sql2+sql3+sql4)
        print sql
        curs.execute(sql)
        curs.close()
        orcl.close()


The put x's in for the sensitive stuff but left all the slashes, comma, quotes etc... the way I have them. I tried several different ways with the slashes because I know python is funny with them but I can't get it to create the view. The statement works in SQLPLus. I am using Python 2.7. Any help is appreciated.

Outcomes