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
1
  • 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 Commented Jun 10, 2020 at 6:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.