Leo
Leo

Reputation: 898

Python: Load Oracle table directly from Pandas (write to Oracle)

Is there any way to load data directly into an Oracle table from Pandas.

Currently I'm writing the data set into a csv file and then loading the table. I would like to bypass "writing to csv" step.

I'm using cx_Oracle for connecting to Oracle database. url is passed as a parameter when calling the python script. result will be stored as a pandas dataframe in variable dataset . The layout of dataset and table definition are same.

    import cx_Oracle as cx
    response = requests.get(url)
    data = response.json()
    dataset = json_normalize(data['results'])

Please let me know if you require any further .

Upvotes: 3

Views: 9369

Answers (1)

user6855124
user6855124

Reputation:

Did you try to_sql function from pandas module?

from sqlalchemy import create_engine
engine = create_engine('oracle://[user]:[pass]@[host]:[port]/[schema]', echo=False)
dataset.to_sql(name='target_table',con=engine ,if_exists = 'append', index=False)

Upvotes: 3

Related Questions