Sometimes as the part of programming, we required to work with the databases because we want to store huge amount of information so we use databases, such as Oracle, MySQL etc. So In this article, we will discuss the connectivity of Oracle database with Python. This can be done through the module name cx_Oracle.
For communicating any database with our Python program, then we required some connector which is nothing but the cx_Oracle module.
For installing cx_Oracle :
pip install cx_Oracle
By this command, you can install cx_Oracle package but it is required to install Oracle database first in your PC.
How to use this module for connection
- Import database specific module
Ex. import cx_Oracle
- connect(): Now Establish a connection between Python program and Oracle database by using connect() function.
con = cx_Oracle.connect('username/password@localhost')
- cursor(): To execute sql query and to provide result some special object required is nothing but cursor() object
cursor = cx_Oracle.cursor()
- execute method :
cursor.execute(sqlquery) – – – -> to execute single query.
cursor.execute(sqlqueries) – – – -> to execute a group of multiple sqlquery seperated by “;”
- commit(): For DML(Data Manuplate Language) query in this query you have (update, insert, delete) operation we need to commit() then only the result reflecte in database.
- Fetch(): This retrieves the next row of a query result set and returns a single sequence, or None if no more rows are available.
- close(): After all done mendentory to close all operation
Table Created successful
Inserting into table:
value inserted successful
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to Install Oracle Database 11g on Windows?
- MYSQLdb Connection in Python
- Connection Between Eigenvectors and Nullspace
- Inserting variables to database table using Python
- Python | Database management in PostgreSQL
- Connect MySQL database using MySQL-Connector Python
- Create a database in MongoDB using Python
- Create MySQL Database Login Page in Python using Tkinter
- Make Python API to access Mongo Atlas Database
- Python - Database Manager (dbm) package
- PostgreSQL - Connect To PostgreSQL Database Server in Python
- PostgreSQL - Connecting to the database using Python
- CRUD Operations on Postgres using Async Database In Python
- Create Database in MariaDB using PyMySQL in Python
- Using Google Sheets as Database in Python
- Extract Data from Database using MySQL-Connector and XAMPP in Python
- Unicodedata – Unicode Database in Python
- Python MySQL - Create Database
- Working with database using Pandas
- Read SQL database table into a Pandas DataFrame using SQLAlchemy
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.