Connect Oracle DB With Python
Connect Oracle DB With Python
I already installed you got softwere from oracle support it is light weight bundle.
import cx_Oracle
Here, we are importing the cx_Oracle module and initializing the Oracle client by providing the path to
the Oracle Instant Client directory. The r prefix before the path indicates a raw string, which is useful
for handling backslashes in Windows paths without escaping them.
username = "PROD"
password = "prod"
host = "DESKTOP-7G8C61I"
port = "1521"
service_name = "orcl"
We're setting the Oracle database connection parameters such as the username, password, host, port,
and service name. Then, you're creating a Data Source Name (DSN) using the makedsn function from
cx_Oracle.
This line establishes a connection to the Oracle database using the provided connection parameters.
cursor = connection.cursor()
We're creating a cursor object. Cursors are used to execute SQL statements and fetch results.
We're executing a simple SQL query to select all rows from the "employee" table, fetching the results,
and then printing each row.
cursor.close()
connection.close()
Finally, you're closing the cursor and the database connection to release resources.
import cx_Oracle
username = "PROD"
password = "prod"
host = "DESKTOP-7G8C61I"
port = "1521"
service_name = "orcl"
# Now you can use the 'connection' object to interact with the Oracle database
cursor = connection.cursor()
cursor.close()
connection.close()