Hackerss.com

hackerss
hackerss

Posted on

Python How to connect to oracle database


#import the module
import cx_Oracle

#create a function
def connect_to_oracle():
    """
    Connect to Oracle database.

    Returns
    -------
    cx_Oracle.Connection
        Connection to Oracle database.
    """

    #connect to Oracle database
    connection = cx_Oracle.connect("username/password@host:port/sid")

    #return the connection
    return connection

#example
connection = connect_to_oracle()
#output
print(connection)  #<cx_Oracle.Connection object at 0x7f8b8d9a5e10>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)