#
# Simple perl script to connect to Oracle database using DBI::Oracle
#
#!/usr/bin/perl -w
# Get the count of the parameters
my $count=@ARGV;
# if paramters are not 3 exit
if ($count!=3) {
print "Usage: ./dbcon.pl [dbname] [user] [password]\n";
exit ;
}
use strict;
use DBI;
# Assign the parameter values to variables
my $db=$ARGV[0];
my $usr=$ARGV[1];
my $pass=$ARGV[2];
# Connect to database
my $dbh=DBI->connect("dbi:Oracle:$db",$usr,$pass)
or die "Connection failed DBI::errstr";
# Prepare the sql statement
my $sql="select name,open_mode,log_mode,database_role from v\$database";
my $sth=$dbh->prepare($sql);
# Execute the sql statement
$sth->execute();
# Fetch the data and dilpay
my @row=$sth->fetchrow_array;
print "Database Details\n";
print "Database Name: $row[0]\n";
print "Database Role: $row[3]\n";
print "Open Mode : $row[1]\n";
print "Log Mode : $row[2]\n";
# Disconnect from the database
$sth->finish();
$dbh->disconnect();
# Output
[oracle@db10g]$ chmod +x dbcon.pl
[oracle@db10g]$ ./dbcon.pl
Usage: ./4.pl [dbname] [user] [password]
[oracle@db10g]$ ./dbcon.pl db10g naikh naikh
Database DetailsDatabase
Name: DUPDB
Database Role: PRIMARY
Open Mode : READ WRITE
Log Mode : ARCHIVELOG
Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts
Monday, December 31, 2007
Monday, December 24, 2007
Perl DBD::Oracle
Installing Perl DBD::Oracle on linux
1. Download DBD::Oracle from the link
http://search.cpan.org/
search for DBD-Oracle in modules
2. Uncompress the downloaded file
$ gunzip DBD-Oracle-1.19.tat[1].gz
3. Untar the file
$ tar -xvf DBD-Oracle-1.19.tat[1]
$ cd DBD-Oracle-1.19
4. Login as root
$ su - root
password: *****
5. Go to DBD-Oracle-1.19 directory
$cd DBD-Oracle-1.19
6. Install the module
$ export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
$ perl MakeFile.PL
$ make
$ make test
$ make intall
$ exit [exit from the root]
1. Download DBD::Oracle from the link
http://search.cpan.org/
search for DBD-Oracle in modules
2. Uncompress the downloaded file
$ gunzip DBD-Oracle-1.19.tat[1].gz
3. Untar the file
$ tar -xvf DBD-Oracle-1.19.tat[1]
$ cd DBD-Oracle-1.19
4. Login as root
$ su - root
password: *****
5. Go to DBD-Oracle-1.19 directory
$cd DBD-Oracle-1.19
6. Install the module
$ export ORACLE_HOME=/opt/oracle/product/10.2.0/db_1
$ perl MakeFile.PL
$ make
$ make test
$ make intall
$ exit [exit from the root]
Subscribe to:
Posts (Atom)