I am new to Python, and was trying to insert excel sheet contents into an oracle database using Python.
I use PowerShell
Here is what I have tried so far without any luck:
import cx_Oracle
import csv
import sys
cx_Oracle.init_oracle_client(lib_dir=r"C:\Users\User\AppData\Local\Programs\Python\Python39")
connection = cx_Oracle.connect( user="username", password="password", dsn="hostname:port/dbname")
cursor=connection.cursor()
with open('c:\oracle\output.csv') as f:
reader=csv.DictReader(f,delimiter=',')
for row in reader:
sqlquery="INSERT INTO table VALUES (%d,'%s','%s','%s')" %(x,row['ORG_NAME'],row['ID'],row['ORGANIZATION_ID'])
cursor.execute(sqlquery)
x=x+1
conn.commit()
Excel sheet only has 3 rows though I am doing it for a test.
Any hints would be much appreciated.
Also tried csv2db but always get the following error:
Error connecting to the database: DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library
I don't get this error when I connect to the database from Python, but when I do csv2db from Powershell I always get this error.
execute(query, values)instead of using%to generateSQLcsv2db? Is this some program installed with Oracle or script in Python? Error can means you have to install some program, and it has to be 64-bit version, not 32-bit version.