Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Help with cx_Oracle
#1
i have a pl/sql contents in a .sql file with some insert/update oracle sql commands in it.
Is it possible in python to call that .sql file and execute contents in it.

testdata.sql file has contents in below format:

SET DEFINE OFF;
DECLARE
BEGIN
update tbl1 set UPD_D = to_date(sysdate-1,'DD-MON-RRRR HH24:MI:SS');
update tbl2 set UPD_DT = to_date(sysdate-1,'DD-MON-RRRR HH24:MI:SS');
COMMIT;
END;
My python code im using it is as below:
import cx_Oracle
import json
import execsql.py

with open('InputData.json') as f:
    global data
    data = json.load(f)

f = open("testdata.sql")
full_sql = f.read()
sql_commands = full_sql.split(';')
conn = cx_Oracle.connect(data["usrid"],data["pwd"],data["conn"])
curs = conn.cursor()
print("Connection Sucess")
curs.execute(full_sql)
Error:
Error on running python code is as below: File "tstsqlfile.py", line 24, in <module> curs.execute(full_sql) DatabaseError: ORA-00933: SQL command not properly ended
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,210 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Installing cx_Oracle 64-bit on AIX Nash 0 1,972 Dec-10-2019, 12:20 AM
Last Post: Nash
  cx_Oracle.DatabaseError: ORA-12541: TNS:no listener ARV 2 10,923 Oct-03-2019, 12:53 PM
Last Post: ARV
  Oracle Merge using cx_oracle raulp2301 0 4,733 Mar-15-2019, 12:56 AM
Last Post: raulp2301
  Help with cx_Oracle anandoracledba 0 3,210 Dec-04-2018, 02:08 AM
Last Post: anandoracledba
  Getting an error while connecting oracle DB from Python : cx_Oracle.DatabaseError: OR dinesh1393 0 3,502 Oct-25-2018, 02:44 PM
Last Post: dinesh1393
  cx_Oracle module not found error PRADEEP 1 3,249 Sep-12-2018, 11:10 AM
Last Post: Larz60+
  Windows server 2008 SP2 - Python cx_Oracle connection DLL error tpanagoda 2 4,997 Mar-05-2018, 04:35 AM
Last Post: tpanagoda
  Pip install error for cx_Oracle kdamundson 2 10,592 Dec-01-2016, 08:11 PM
Last Post: kdamundson
  ORA-03113: end-of-file on communication channel Python Cx_Oracle akansha 3 7,482 Nov-17-2016, 08:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020