Search code examples
pythonsqloracle-databasepandassqlalchemy

How access objects (tables) of Other Users in Oracle DB using Python tools (SQLAlchemy, cx_Oracle, etc.)?


I have read access to other users' tables. How can I read them into pandas dataframe or just download as *.csv using Python tools?


Solution

  • You need to install cx_oracle and SQLAlchemy.

    import cx_Oracle
    import sqlalchemy as sa
    import pandas as pd
    
    engine = sa.create_engine ('oracle+cx_oracle://user:pwd@host:port/dbname')
    connection = engine.connect()
    df = pd.read_sql("select * from otheruser.table", connection)
    df.head()
    df.to_csv("file.csv")