Nitin Alety
Nitin Alety

Reputation: 25

how to print the names of tables of database using perl scripting using unix

How to print the names of tables of database using Perl scripting using unix. Connected to DB using DBI module.

I tried scripting using

     my $driver= "Oracle";
     my $dsn = "DBI:$driver:sid=as;host=asdsa";
     my $dbh = DBI->connect($dsn, "a", "b") || die( $DBI::errstr . "\n" );
     my $notables = $dbh->tables();
     print "No of tables : $notables" ;

Getting error:

Can't call method "tables" on an undefined value at hello.pl line 16.

Please help.

Upvotes: 0

Views: 520

Answers (1)

ilux
ilux

Reputation: 367

Looks like you not connected to DB.

Read DBI documentation and try something like this:

use DBI;
use Data::Dumper;

my $dbh = DBI->connect($data_source, $username, $password)
          or die $DBI::errstr;

my @names = $dbh->tables( $catalog, $schema, $table, $type );
print Dumper @names;

$dbh->tables; without args is deprecated

Upvotes: 1

Related Questions