DAY 13 - Import data dynamically from Oracle DB using Python script in Power BI Desktop

DAY 13 - Import data dynamically from Oracle DB using Python script in Power BI Desktop

Step 1 : Python IDLE  & Power BI need to be installed in your system

Step 2: Execute the below script independetly in Python IDLE and make sure it's getting executed successfully.

import cx_Oracle
import pandas as pd


connection = None
try:
    #Oracle DB Connection Details
 
    username = 'p_user_name'
    password = 'p_password'
    dsn = 'hostname:port_number/service_name'
 

    connection = cx_Oracle.connect(
        username,
        password,
        dsn)
 


    # show the version of the Oracle Database
    #print(connection.version)
 
    cur = connection.cursor()
    cur.execute("select * from oe_order_headers_all where rownum <=10") #fetching 10 records from Order Header Table
    res = cur.fetchall()
 
    #store data into a dataframe. We are going to use this dataframe as a dataset in POWER BI
    df = pd.DataFrame(res)
    df
 
 
    #logic to print each record
    for row in res:
       pass
       #print(row)
    cur.close()
except cx_Oracle.Error as error:
    print(error)
finally:
    # release the connection
    if connection:
        connection.close()
       
       
Step 3: Open POWER BI DESKTOP Tool and Navigate to File > Options and Settings > Options > GLOBAL > Python Scripting (Preview features and ensure Python Support option is checked)



Step 4 : Navigate to Home > Get data > More.. > Other > Python Script > Connect



Step 5 : A new pop up window will appear where you have to enter the above python script  and click on OK



Step 6 : Select dataframe# df in the Navigator dialogue and click Load.



Data will be loaded in the Power BI successfully. Tada 🎉🎉



#RR #Day13 #Python #ConnectionToOracleDB #ConnectToOracleDBUsingPythonInPowerBI #PowerBI #HappyLearning #WeLearnEveryday

Comments

Popular posts from this blog

Day 32 - Python Script to track Available COVID-19 Vaccine Slots for 18+ in India

DAY 1 - Steps to prepare your windows laptop for Python Programming

Day 26 - Call Power BI REST APIs to get POWER BI REPORT Details