SQL 和 Python 错误 - table 或视图不存在

Error with SQL and Python - table or view does not exist

如果我在 Python 的 sql 查询中添加 left JOIN t2 ON Col10 = Col1 作为命令,我将无法 运行 脚本。没有它我可以运行脚本没有问题。

我得到的错误是:SQL错误:ORA-00942table或视图不存在

PS- 脚本完整脚本在 SQL 开发人员中运行良好。

有什么建议吗?

import cx_Oracle
import pandas as pd

conn = cx_Oracle.connect('......')

cur = conn.cursor()

sql = "SELECT \
    Col1, \
    Col2 \
    FROM t1 \
    left JOIN t2 ON Col10 = Col1"

cur.execute(sql)

sql_data = pd.DataFrame(cur.fetchall())
col_names = [row[0] for row in cur.description]
sql_data.columns = col_names
sql_data

PS- The full script is working fine in SQL developer.

如果是这样,则意味着用户 - 您在 SQL 开发人员中连接 - 可以访问 t1t2 table。


如果 Oracle 抱怨

ORA-00942 table or view does not exist

当您 运行 来自 Python 的相同 SELECT 语句时,这意味着您现在连接到的用户

conn = cx_Oracle.connect('......')

没有权限访问 t2 table。那可能是因为

  • 你拼错了它的名字
  • 有人删除了 table,因此它不再存在于该架构中
  • 它归其他人所有,但您访问它是因为所有者授予您这样做的权限(现在这些权限已被撤销)
  • 您将其用作 public 已删除的同义词

或者其他原因。很难调试您发布的“通用”代码,显然,table 不是真正的 t1 也不是 t2 并且列不是 col1 也不是 col2等。因此,re-read我刚才所说的并试图找到罪魁祸首。祝你好运!