0

I am trying to pass the parameter to the SQL script from python.

below is the script I am trying; please let me know what I am doing wrong here...

#!./bin/python
_author_='Mohammed'

import boto3
import cx_Oracle
import sys

con = cx_Oracle.connect('username/password@localhost:1521/DBName')
print con.version
cur=con.cursor()
statements = open('$location/test.sql').read().format('localhost')
cur.execute(statements)
query_result=cur.fetchall()
for res in query_result:
print(res)

************Error***********

Traceback (most recent call last):
  File "$location\test1.py", line 19, in <module>
    statements = open('$location/test.sql').read().format('localhost')
IndexError: tuple index out of range
3
  • cx_Oracle (and other language APIs such as node-oracledb) let you execute one SQL statement at a time. These APIs do not do batch-script execution. You need to split your statements up in Python (or store them in some other separate way) and then pass them one at a time to cx_Oracle's cur.execute(). You may also be able to use PL/SQL to do things like: begin execute immediate 'create user testuser identified by testuserpwd'; execute immediate 'grant connect, create session to testuser'; end; Commented Nov 14, 2017 at 4:12
  • can we use subprocess do it.. Commented Nov 14, 2017 at 23:19
  • I prefer doing it all natively in Python because then you have better error control. Commented Nov 15, 2017 at 1:32

0

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.