Difference between revisions of "PERL Scripts for Databases"

From Minor Miracle Software
Jump to: navigation, search
(Created page with " =PERL DBD::Oracle Connection= This works without a tnsnames.ora file. <nowiki> #!/usr/bin/perl # Connecting without a tns use warnings ; use strict ; use DBI; $\="\n"; pr...")
 
(No difference)

Latest revision as of 14:13, 31 March 2021

PERL DBD::Oracle Connection

This works without a tnsnames.ora file.

#!/usr/bin/perl 
# Connecting without a tns
use warnings ;
use strict ;
use DBI;

$\="\n";

print "Connecting to WOTRS10...";

my $dbh = DBI->connect('dbi:Oracle:host=localhost;SERVICE_NAME=XEPDB1;port=1521', 'wotrs10','orawotrs10') or
          die "Cannot connect to WOTRS10 => " . DBI->errstr;
my $sth = $dbh->prepare("select name from activities") or
          die "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute();

while (my ($f_name) = $sth->fetchrow_array()){
    printf "Activity Name : %-10s\n" , $f_name;
}
#$sth->finish();
$dbh->disconnect();
# Hostname: localhost
# Port: 1521
# Service name: XEPDB1

Internal Links

Parent Article: Databases