To link any database with our Python program, we needed some kind of connector, which is nothing other than module cx_Oracle .
To install cx_Oracle:
pip install cx_Oracle
With this command you can install the cx_Oracle package , but first you need to install the Oracle database on your PC.
How to use this module to connect
- Import a specific module database
Ex. import cx_Oracle
- connect (): now connect the Python program to the Oracle database using the connect () function.
con = cx_Oracle.connect (’username / password @ localhost’)
- cursor (): to execute the sql query and provide the result, some special object is required — 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 a DML (Data Manuplate Language) query in this query, you have an operation (update, insert, delete), we need commit (), then only the result is reflected in the database.
- Fetch (): fetches the next row from the query result set and returns one sequence, or None if there are no more rows available.
- close (): after all submenus are done to close all operations
cursor.close () con.close ()
Table Created successful
Insert into table:
value inserted successful