如何使用unix使用perl脚本打印数据库表的名称

如何使用unix使用perl脚本打印数据库表的名称,perl,Perl,如何使用unix使用Perl脚本打印数据库表的名称。使用DBI模块连接到数据库 我尝试使用脚本编写 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(); pri

如何使用unix使用Perl脚本打印数据库表的名称。使用DBI模块连接到数据库

我尝试使用脚本编写

     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" ;
获取错误:

无法对hello.pl第16行的未定义值调用方法表


请帮助。

看起来您没有连接到数据库

阅读文档并尝试以下方法:

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;如果没有args,则不推荐使用

未定义$dbh对象。您确定已连接到数据库吗?请回答您的问题,并包括执行我的$dbh=DBI->connect的部分。或者更好,包括完整的程序。还可以查看以了解如何格式化问题中的代码。是,已连接到db。。更新了代码。这真的是产生此错误的代码吗?我觉得不太可能。对connect的调用将返回数据库句柄或undef。返回undef将触发die调用,因此您必须从connect获取定义的数据库句柄。我怀疑您为了简化示例而删除的部分代码中还有其他内容。