PERL Scripts for Databases

From Minor Miracle Software
Jump to: navigation, search

PERL DBD::Oracle Connection

This works without a tnsnames.ora file.

# Connecting without a tns
use warnings ;
use strict ;
use DBI;


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;

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

Internal Links

Parent Article: Databases