0

Below is an example of a SQL Developer query I'd like to run from Python.

sqlQuery = """
DEFINE a = 1
DEFINE b = 2

select &&a + &&b from dual
"""
result = pandas.read_sql(sql=sqlQuery, con=Oracle_Connection) 

This query works when I run it inside of SQL Developer, however when I run the above code in Python, I get the following error: 'ORA-00900: invalid SQL statement'. Is there an easy fix I can make to resolve this?

1 Answer 1

1
DEFINE a = 1
DEFINE b = 2

DEFINE is a command of SQL*Plus or SQLDeveloper, that is not SQL command. You need to use bind variables instead:

select :a + :b from dual;

Full example:

sqlQuery = """
select :a + :b from dual
"""
result = pandas.read_sql(sql=sqlQuery, con=Oracle_Connection, params={'a': 1, 'b': 2})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.