0

I try to import data from a oracle database to a pandas dataframe.

right Now i am using:

import cx_Oracle
import pandas as pd
db_connection_string = '.../A1@server:port/servername'
con = cx_Oracle.connect(db_connection_string)
query = """SELECT* 
           FROM Salesdata"""
df = pd.read_sql(query, con=con)

and get the following error: DatabaseError: ORA-00942: Table or view doesn't exist

When I run a query to get the list of all tables:

cur = con.cursor()
cur.execute("SELECT table_name  FROM dba_tables")
for row in cur:
    print (row)

The output looks like this:

('A$',)
('A$BD',)
('Salesdata',)

What I am doing wrong? I used this question to start.

If I use the comment to print(query)I get:

SELECT* 
           FROM Salesdata
Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
PV8
  • 5,799
  • 7
  • 43
  • 87
  • 1
    Comment out your data frame df and print the query. print(query). Check what is the result. This would make us understand the issue – Jim Macaulay Jun 10 '20 at 06:34

1 Answers1

1

Getting ORA-00942 when running SELECT can have 2 possible causes:

  1. The table does not exist: here you should make sure the table name is prefixed by the table owner (schema name) as in select * from owner_name.table_name. This is generally needed if the current Oracle user connected is not the table owner.

  2. You don't have SELECT privileges on the table. This is also generally needed if the current Oracle user connected is not the table owner.

You need to check both.

pifor
  • 7,419
  • 2
  • 8
  • 16