0

I am newbie to oracle and I am trying to make a connection from python to an oracle table.

I can use Toad for oracle to access to the data of one table. I am running the same SQL command through python and I get the "DatabaseError: ORA-00942: table or view does not exist". I have search a lot and still do not know what the issue is:

I setup my connection:

import cx_Oracle
con = cx_Oracle.connect(<user>,<password>,<database name>)
print("Database version:", con.version)

Successful connection

I set my current schema

con.current_schema = 'schema_name'

and

cursor = con.cursor()
cursor.execute('select du.cfile_id from table_name du')

This throws an error of:

---------------------------------------------------------------------------
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

Same query with same credential is working fine if I use "Toad for oracle". Note that I require to put "exec schema.PKG_DVS_ACCESS.get" before running my data extract on Toad. How should I include the command to my python code?

Thanks

1 Answer 1

1

To call PL/SQL procedures and packages in cx_Oracle use callproc:

cursor.callproc('myproc')

If the PL/SQL procedure has parameters, you will have to bind data values.

myvar = cur.var(int)
cur.callproc('myproc', (123, myvar))
print(myvar.getvalue())

Take a look at the cx_Oracle tutorial.

Update: A new blog post from Oracle talks more about using PL/SQL with cx_Oracle.

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

1 Comment

Thanks a lot for the help.

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.