PERL Scripts for Databases
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