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
georgexsh
  • 15,984
  • 2
  • 37
  • 62
Mohammed
  • 49
  • 1
  • 1
  • 6
  • 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; – Christopher Jones Nov 14 '17 at 04:12
  • can we use subprocess do it.. – Mohammed Nov 14 '17 at 23:19
  • I prefer doing it all natively in Python because then you have better error control. – Christopher Jones Nov 15 '17 at 01:32

0 Answers0