#!/usr/bin/perl # ################################################################# # # Project: DBI Module # # Filename: sqlplus.pl # # Version: 1.0 # # Autor: Akadia AG, Martin Zahn 27.12.1999 # # Synopsis: sqlplus.pl # # Purpose: This perl scripts is "nearly" an SQL*PLUS # # ################################################################# use DBI; $dbname = 'RAB1'; $user = 'scott'; $password = 'tiger'; $dbd = 'Oracle'; $dbh = DBI->connect($dbname,$user,$password,$dbd) || die "Error connecting $DBI::errstr\n";; while(1) { print "MYSQL> "; # SQL-Prompt $stmt = ; last unless defined($stmt); last if ($stmt =~ /^\s*exit/); chomp ($stmt); $stmt =~ s/;\s*$//; $sth = $dbh->prepare($stmt); if ($DBI::err) { print STDERR "$DBI::errstr\n"; next; } $sth->execute() ; if ($DBI::err) { print STDERR "$DBI::errstr\n"; next; } if ($stmt =~ /^\s*select/i) { my $rl_names = $sth->{NAME}; # Reference to List of colum names while (@results = $sth->fetchrow) { # Retrieve results if ($DBI::err) { print STDERR $DBI::errstr,"\n"; last; } foreach $field_name (@$rl_names) { printf "%10s: %s\n", $field_name, shift @results; } print "\n"; } $sth->finish; } } $dbh->commit;