Data Science | Quickly Connect Oracle With Python Code

To connect Oracle SQL with Python, you will need to install the following libraries: cx_Oracle: This is a Python extension module that enables access to Oracle Database. You can install it using pip:

    
        Pip install cx_Oracle
    

Oracle Instant Client: This is a free Oracle client that allows you to connect to Oracle Database. You can download it from the Oracle website (https://www.oracle.com/database/technologies/instant-client/downloads.html). Once you have these libraries installed, you can use the following Python code to connect to Oracle Database:

Want to learn more about Machine Learning?

I share tips and tricks in my blog that I have learnt in over and a half decade. I share practical use of Machine Learning that I use in my daily project. My blog is further categorised into four distinct areas including Tourism, Education, Machine Learning, and Health. 


                    import cx_Oracle

                    # Connect to Oracle Database
                    conn = cx_Oracle.connect("username/password@host:port/service_name")

                    # Create a cursor
                    cursor = conn.cursor()

                    # Execute a SQL statement
                    cursor.execute("SELECT * FROM employees")

                    # Fetch the rows
                    rows = cursor.fetchall()

                    # Loop through the rows and print the results
                    for row in rows:
                        print(row)

                    # Close the cursor and connection
                    cursor.close()
                    conn.close()


Replace “username/password@host:port/service_name” with the appropriate values for your Oracle Database. The “username” and “password” should be the credentials you use to log in to the database, “host” is the hostname or IP address of the machine where the database is running, “port” is the port number on which the database is listening, and “service_name” is the Oracle service name. You can then use the cursor object to execute SQL statements and fetch the results. I hope this helps! Let me know if you have any questions.

————————–

THIS POST IS WRITTEN BY SYED LUQMAN, A DATA SCIENTIST FROM SHEFFIELDSOUTH YORKSHIRE, AND DERBYSHIREUNITED KINGDOMSYED LUQMAN IS OXFORD UNIVERSITY ALUMNI AND WORKS AS A DATA SCIENTIST FOR A LOCAL COMPANY. SYED LUQMAN HAS FOUNDED INNOVATIVE COMPANY IN THE SPACE OF HEALTH SCIENCES TO SOLVE THE EVER RISING PROBLEMS OF STAFF MANAGEMENT IN NATIONAL HEALTH SERVICES (NHS). YOU CAN CONTACT SYED LUQMAN ON HIS TWITTER, AND LINKEDIN. PLEASE ALSO LIKE AND SUBSCRIBE MY YOUTUBE CHANNEL.

Leave a Comment

Your email address will not be published. Required fields are marked *

×

Hey!

Please click below to start the chat!

× Let's chat?