DCOracle and sqlplus?

Thomas A. Bryan tbryan at python.com
Wed Oct 25 06:43:16 EDT 2000


Erik Myllymaki wrote:

> I am quite new to Oracle and don't know how I would go about using a
> pre-written sqlplus report through DCOracle. I am guessing I can't use
> DCOracle for this at all but would have to hit sqlplus from a command-line
> call and bring the text in that way.

That depends what you mean by "a pre-written sqlplus report."  If you just 
mean that someone has written a bunch of SQL and PL/SQL and put it in a file 
for you to run like 

SQL> @report1

at the sqlplus prompt, then you can probably migrate some or all of it to 
Python using DCOracle.  I believe that you can call a PL/SQL block using 
DCOracle, but I'm not sure whether I have ever done it.  Once I have Python 
in the picture, I usually do all of the scrolling through cursors in Python.

If the report has a bunch of commands for sqlplus to do things like set up 
the sqlplus environment so that the output looks right (doesn't line-wrap, etc.), 
then you'll need to modify the report before running it in Python.  

In fact, I'm not sure why you'd bother replicating an existing sqlplus report 
in Python unless you plan to gain something by it.  Are you simply having fun 
with using Python, or are you replacing all sqlplus scripts with Python to 
restrict direct database access.  You may also be planning to process the data 
within Python to do some nifty computations or to customize the output, such as 
using the Win32 extensions to write the output into a spreadsheet.
 
Each command in a sqlplus script is 
1) an SQL command (trivial to move into Python)
2) a part of a PL/SQL block (you may want to translate it to Python)
3) a command to the sqlplus environment (drop these and either replicate the 
intent in Python or ignore them, depending on your goal)

> Any examples or advice would be greatly appreciated.

Post an example or a simplified example of what you're trying to do and why 
you're trying to do it, and it would be much easier to give you appropriate 
examples. :)  

---Tom



More information about the Python-list mailing list