I want to load a very large dataset into the Oracle database using Python. For Microsoft SQL, I used SQLALchemy and I was superfast. I want to use the same procedure for the Oracle as follows
import cx_Oracle
from sqlalchemy import create_engine
import sqlalchemy
dsn = cx_Oracle.makedsn(host, port,service_name)
engine = create_engine(
f'oracle://{<username>}:{<password>}@{dsn}', max_identifier_length=128)
df.to_sql(table_name, engine, index=False, if_exists="replace")
This throws an error as follows:
DatabaseError: (cx_oracle.DatabaseError) ORA-01031: insufficient privileges [SQL: CREATE TABLE ....
Interestingly, we used the same user and load a dataset from sqlplus and it worked there but here it returns back an error.
I should mention that I can read the data from oracle like the below one:
pd.read_sql_query("""SELECT * FROM <TABLE_NAME>""")
To solve this issue I tried the following code:
cursor.execute("""grant insert on <table_name> to <user>""")
But, this one also returns the following error
ORA-01749: you may not GRANT/REVOKE privileges to/from yourself
Do you have any solutions? Please note that I used the same userid and loaded the data into oracle somewhere else.
Here are the privileges that are currently available for the user:
SELECT * FROM session_privs
- CREATE SESSION
- UNLIMITED TABLESPACE
The final solution for me:
- use the lower case of table name (I do not why)
- use if_exists = "append"
Of course, it is required to truncate the records before appending, for that, I used a procedure that was already available in our oracle serve (using
cursor.callproc()
).TRUNCATE TABLE <TABLE_NAME>
did not work.