Do you really need to execute your commands via SQL*Plus ?  Many of the
things you can do in SQL*Plus you can do using DBI.  If you definitely
need SQL*Plus, here are a couple of ways of using it ...

(fork a child process then exec sqlplus from the child.  This is a
snippet from an existing program)
                        :
                        unless ($Started_SQLPlus) {
                                my $pid ;
                                if ($pid = open(SQLPLUS, "|-")) {
                                        SQLPLUS->autoflush(1) ;
                                } else {
                                        { exec '$ORACLE_HOME/bin/sqlplus
-s' ; }
                                        croak "exec failed - $!\n" ;
                                }
                                print SQLPLUS $DB->uidpwd, "\n" ;
                                print SQLPLUS "set feedback off\n" ;
                                $Started_SQLPlus = 1 ;
                        }
                        print SQLPLUS "$sql\n/\n" ;
                        :

(using IPC::Open3 - this is a complete albeit crappy example script)

use IO::Handle ;
use IO::Select ;
use IPC::Open3 qw (open3) ;

my $plus_in = IO::Handle->new ;
my $plus_out = IO::Handle->new ;
STDOUT->autoflush(1) ;
$plus_in->autoflush(1) ;
$plus_out->autoflush(1) ;
my $ios = IO::Select->new ;
my $pid = open3($plus_out, $plus_in, 0, "sqlplus") ;
$ios->add($plus_in) ;
$plus_in->blocking(0) ;
check_sqlplus_feedback() ;
$plus_out->print("scott/tiger\n") ;
check_sqlplus_feedback() ;
$plus_out->print("select * from dual;\n") ;
check_sqlplus_feedback() ;
$plus_out->print("exit\n") ;
check_sqlplus_feedback() ;
$plus_in->close ;
$plus_out->close ;

sub check_sqlplus_feedback {
        while (my @ready = $ios->can_read(1)) {
                foreach (@ready) {
                        if ($_->eof) {
                                $_->close ;
                                last ;
                        }
                        my $buf ;
                        $_->read($buf, 256) ;
                        print $buf ;
                }
        }
}


-----Original Message-----
From: Mayes, Iman [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 30 December 2003 1:05 AM
To: [EMAIL PROTECTED]; dbi-users
Subject: RE: Automatng import


Hi,

Here is a little something I do to execute sqlplus commands from shell
scripts. This is just a snippet from a database startup script, so
you'll have to season to taste. This should get you started in the right
direction.

sqlplus /nolog <<EOF
connect / as sysdba
startup
EOF

Hope this helps

Iman

-----Original Message-----
From: John [mailto:[EMAIL PROTECTED]
Sent: Friday, December 26, 2003 3:38 PM
To: dbi-users
Subject: Re: Automatng import


Quoting Kevin Moore <[EMAIL PROTECTED]>:

> Try  "drop user jim cascade"
> 
> John wrote:
> 
> >Hi all
> >
> >I am planning to make a cronjob so i would like to know if tht can be
> achived through a perl script.
> >
> >To be more specific, i have an Oracle RDBMS and i want to execute 
> >some
> commands in the shell
> >
> >.....
> >system("sqlplus system/password");
> >system("drop jim cascade");
> >........
> >
> >
> >can be the above done? To execute internal commands as the sqlplus 
> >programs
> provides?
> >  
> >
> 
> 

I am afraid that this trick isn't going to work as far as system() will
be waiting until the sqlplus command ends.

What do you say?

Reply via email to