Executing Sql query in a Perl script
Below is the example. Here we can execute a sql query or a sybase query in a perl script. Please also note that I am not utilizing the DBI module provided by perl.#!/usr/bin/perl use strict; use warnings; my $result = qx { isql -Uxx -Pxxxxxxx -Dxxxx <<EOF set nocount on select count(*) from XXX go exit EOF }; print $result;Above example show connecting to the sybase database. If you are using Oracle DB, then you can change the connection string:
isql -Uxx -Pxxxxxxx -Dxxxx
to
sqlplus....Note:
One strange thing over here never add spaces at the begining of the line after the statement isql.....<<EOF
the query will not be executed in such case you will go nuts trying to figure out why!
Really a Great post, thanks for sharing .keep it up.
ReplyDeletePERL Scripting Online Training