Wednesday, April 7, 2010

executing sql file though perl

The code is simple , no big deal . just documenting for possible reuse next time.
The blog just does not let me put the lessthan greaterthan symbol.

#!/usr/bin/perl

use Getopt::Std;

%options=();
getopts("s:",\%options);

&usage if (! defined( $options{s} ) );

my $sqlfile = $options{s};

my $login_file = "/home/reiki/.dev_login";
open (IP,"$login_file") || die "Cannot open file $login_file $!";
my $user_pass = ;
close IP;


open ORA, "| /oracle/reikidev/app/product/10.2.0/bin/sqlplus -s $user_pass" or die "Can't pipe to sqlplus: $!";
print ORA "set trimspool on echo on pagesize 500 linesize 20000 colsep ' '\n";

open (SF,"$sqlfile") || die "Cannot open file $sqlfile $!";
while (my $line = ) {
print ORA "$line";
}

print ORA "exit\n";
close ORA;
close SF;


sub usage {
print "usage: ./ut_reiki_exec_sql.pl -s sqlfile\n";
exit;
}

No comments:

Post a Comment

Followers

About Me

Torrance, CA, United States