Error ORA-00933 when using oracle query in python

0

I'm putting together a script in python:

#!/usr/bin/python2.6
import os
import cx_Oracle
import csv

SQL="SELECT count(status) status FROM  v'$'session GROUP BY status"


# You can set these in system variables but just in case you didnt
os.putenv('ORACLE_HOME', '/oracle/product/10.2.0/db_1')
os.putenv('LD_LIBRARY_PATH', '/oracle/product/10.2.0/db_1/lib')

connection = cx_Oracle.connect('XXX/XXX:XXX/XXX')

cursor = connection.cursor()
cursor.execute(SQL)
for row in cursor:
    print row
cursor.close()
connection.close()
FILE.close()

and it returns me the error ORA-00933, saying that the query is badly finished.

    
asked by Cristian Sanchez 14.04.2016 в 21:56
source

1 answer

1

In the line where you generate the query, you just have to remove the apostrophes where you select the session table

#!/usr/bin/python2.6
import os
import cx_Oracle
import csv

SQL="SELECT count(status) status FROM  v$session GROUP BY status" ## Aquí esta el cambio


# You can set these in system variables but just in case you didnt
os.putenv('ORACLE_HOME', '/oracle/product/10.2.0/db_1')
os.putenv('LD_LIBRARY_PATH', '/oracle/product/10.2.0/db_1/lib')

connection = cx_Oracle.connect('XXX/XXX:XXX/XXX')

cursor = connection.cursor()
cursor.execute(SQL)
for row in cursor:
    print row
cursor.close()
connection.close()
FILE.close() 

Here is a query very similar to yours on which you can base

    
answered by 14.04.2016 в 23:21