DEV Community

Cover image for Saving Dataframes into Oracle Database with Python
Luca Liu
Luca Liu

Posted on β€’ Edited on

7

Saving Dataframes into Oracle Database with Python

Using Python to Save a Dataframe into Oracle Database

You can use the pandas library in combination with the sqlalchemy and cx_Oracle libraries to save a dataframe to an Oracle database in Python.



import pandas as pd
from sqlalchemy import create_engine
import cx_Oracle

# Create an SQLAlchemy engine using the connection
engine = create_engine('oracle://username:password@hostname:port/service_name')

# Save the dataframe to the Oracle database and lowercase your_table_name 
df.to_sql('your_table_name', con=engine, if_exists='replace', index=False)


Enter fullscreen mode Exit fullscreen mode

Replace 'username', 'password', 'hostname', 'port', and 'service_name' with your actual Oracle database credentials, connection details.

Please replace your_table_name with the actual lowercase name of the table in your Oracle database. Otherwise, you may encounter InvalidRequestError: Could not reflect: requested table(s) not available in Engine.

When you run this script, it will establish a connection to the Oracle database, create a sample dataframe, and then save the dataframe to the specified table in the Oracle database.


Explore more

Thank you for taking the time to explore data-related insights with me. I appreciate your engagement.

πŸš€ Connect with me on LinkedIn

πŸŽƒ Connect with me on X

🌍 Connect with me on Instagram

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay