我是oracle的新手,我正在尝试建立从python到oracle表的连接。
我可以使用Toad for oracle来访问一个表的数据。我通过python运行相同的SQL命令,得到"DatabaseError: ORA-00942:表或视图不存在“。我已经搜索了很多次,但仍然不知道问题是什么:
我设置我的连接:
import cx_Oracle
con = cx_Oracle.connect(<user>,<password>,<database name>)
print("Database version:", con.version)
连接成功
我设置了我当前的模式
con.current_schema = 'schema_name'
和
cursor = con.cursor()
cursor.execute('select du.cfile_id from table_name du')
这将抛出以下错误:
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call last)
<ipython-input-195-f3f5aacf8431> in <module>()
----> 1 cursor.execute('select du.cfile_id from brwr_tau_to_du_log du')
DatabaseError: ORA-00942: table or view does not exist
如果我使用"Toad for oracle“,使用相同凭据的相同查询可以正常工作。请注意,在Toad上运行数据提取之前,我需要设置"exec schema.PKG_DVS_ACCESS.get“。我应该如何在我的python代码中包含这个命令?
谢谢
发布于 2018-07-27 11:00:08
要在cx_Oracle中调用PL/SQL过程和包,请使用callproc
cursor.callproc('myproc')
如果PL/SQL过程有参数,则必须绑定数据值。
myvar = cur.var(int)
cur.callproc('myproc', (123, myvar))
print(myvar.getvalue())
更新:来自Oracle的新blog post谈到了更多关于在cx_Oracle中使用PL/SQL的内容。
https://stackoverflow.com/questions/51539132
复制相似问题