0

I wrote this function to take in three parameters and a database connection, execute a function, and then pull from a view that is populated by the function.

def get_customer_data(start_date, end_date, segment, con):
    """ Get customer data
    """

    # This executes a process in the database that populates
    # my_view which we will subsequently pull from.
    sql = """EXEC PROCESS_POPULATE_VIEW ('%s','%s','%s');
    """ % (str(start_date), str(end_date), segment)

    con.execute(sql)

    sql = "SELECT * FROM MY_VIEW"

    return pd.read_sql(sql, con)

This is what I get back:

DatabaseError: (cx_Oracle.DatabaseError) ORA-00900: invalid SQL statement [SQL: "EXEC PROCESS_POPULATE_VIEW ('11-JUN-2018','13-JUN-2018','Carrier');\n    "] (Background on this error at: http://sqlalche.me/e/4xp6)

Am I not allowed to call the EXEC command from sqlalchemy? Is there a workaround for this?

Jon M
  • 164
  • 1
  • 12
  • 2
    EXEC is a SQL\*Plus command, not SQL. – APC Jul 21 '18 at 02:04
  • (i) use BEGIN and END around the PL/SQL procedure name (ii) pass the parameters by using bind variables instead of insecure and unscalable string concatenation. See the sample or tutorial https://github.com/oracle/python-cx_Oracle/tree/master/samples/tutorial – Christopher Jones Jul 24 '18 at 06:09

0 Answers0