On Tue, 11 Nov 2003 07:44:16 -0800 Kevin Moore <[EMAIL PROTECTED]>
wrote:

> Since I've got no experience with OCI and not much play time right
> now I'm going to ask this question. Can you execute a command line
> shell script using OCI? If so there is no reason you cannot invoke
> sqlplus and startup or shutdown an Oracle database.

Not using OCI, but Perl can run SQL*Plus very nicely.  While waiting
for a large company to install DBI several years ago, I wrote a fairly
robust Oracle SQL executer using SQL*Plus from Perl.

The main trick was to pipe the commands in and send the output to a
pipe.  It could also go to a file using shell redirection.

# From memory, not tested
use IPC::Open3 qw( open3 );
use IO::File;
my $in  = IO::File -> new();
my $out = IO::File -> new();
my $pid = open3( $out, $in, "", "sqlplus", "/nolog" );
$out -> print <<END_STARTUP;
CONNECT / AS SYSDBA
STARTUP
PROMPT DONE
END_STARTUP
while ( <$in> ) {
   s/\s+$//;
   last if "DONE" eq $_;
   print "$_\n";
}

# Do something else with the active SQL*Plus session

$out -> print <<SHUTDOWN;
CONNECT / AS SYSDBA
SHUTDOWN
PROMPT DONE
EXIT
END_SHUTDOWN
while ( <$in> ) {
   s/\s+$//;
   last if "DONE" eq $_;
   print "$_\n";
}

-- 
Mac :})
** I usually forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

Reply via email to