Python embebbed with Oracle SQL*Plus

Olav olavb at yahoo.com
Thu Jun 28 07:38:03 EDT 2001


"James T. Dennis" <jadestar at idiom.com> wrote in message news:<9hebu5$12lo$1 at news.idiom.com>...
> In comp.lang.python Olav <olavb at yahoo.com> wrote:
> 
> > Some time ago I did some Oracle SQL*Plus on UNIX, 
> > and I was able to write quite powerful scripts 
> > embebbed in ksh (Korn Shell).
>  
> > Is something similar possible with Python?
> 
> 	I presume your ksh scripts were passing
> 	SQL code to an sql command (possibly in
> 	the form of "here" documents).
> 
> 	For course you can build arbitrary commands
> 	in Python and invoke the system to execute
> 	them.  (sys.system()?).

This is a very simple Cygwin/NT example:
***************
PLUS33 scott/tiger at prod_sa <<EOF 
select COU_NAME from M1_countries
/
quit
eof
********************
So it is not simply building an SQL-string and calling
some function.

It is really like SQL embedded in the script.
There are also mechanism for passing variables back and forth.
(I can easily write a script that takes a sql-statement as an arguments
from the command line, something like osql select "*" from M1_countries)

Typically what I use it for is regression-testing.  I pass arguments
on the command line to the script, execute an SQL-statement and run
the output through sort, grep, diff etc. 

I guess the mechanism is to build a temporary file, and call sqlplus
with this.

I think it might be more difficult with Python because it is actually 
precompiled and because there is no equivalent of pipes.

**
Olav



More information about the Python-list mailing list