perl 无法打印所需的输出
perl not able print desired output
您好,我正在编写一个 perl 脚本以使用 SQL Plus 连接到数据库,但是当我查询数据时,它没有显示正确的输出,有人可以解释一下吗?
$ perl test.pl -u user -p paswd -d database
while ($ARGV[0] =~ /^-/)
{
$opt = shift;
$dbuser = shift if ($opt eq "-u");
$dbpasswd = shift if ($opt eq "-p");
$db = shift if ($opt eq "-d");
}
$output=`echo "select sysdate from dual" | sqlplus $dbuser\/$dbpasswd\@$db`;
print $output;
输出屏幕:我希望输出为 sysdate。
SQL*Plus: Release 11.2.0.3.0 Production on Mon Feb 25 13:13:38 2019
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> SQL> 2 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
我认为缺少 ;
$output=`echo "select sysdate from dual;" | sqlplus $dbuser\/$dbpasswd\@$db`;
Sqlplus 需要许多设置才能使用。我建议:
$output=`( echo "set heading off" ; echo "set feedback off" ; echo "set newpage none" ; echo "set pagesize 0" ; echo "select sysdate from dual;" ) | sqlplus -s $dbuser\/$dbpasswd\@$db`;
别忘了咬住结果:
chomp $output
您好,我正在编写一个 perl 脚本以使用 SQL Plus 连接到数据库,但是当我查询数据时,它没有显示正确的输出,有人可以解释一下吗?
$ perl test.pl -u user -p paswd -d database
while ($ARGV[0] =~ /^-/)
{
$opt = shift;
$dbuser = shift if ($opt eq "-u");
$dbpasswd = shift if ($opt eq "-p");
$db = shift if ($opt eq "-d");
}
$output=`echo "select sysdate from dual" | sqlplus $dbuser\/$dbpasswd\@$db`;
print $output;
输出屏幕:我希望输出为 sysdate。
SQL*Plus: Release 11.2.0.3.0 Production on Mon Feb 25 13:13:38 2019
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> SQL> 2 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
我认为缺少 ;
$output=`echo "select sysdate from dual;" | sqlplus $dbuser\/$dbpasswd\@$db`;
Sqlplus 需要许多设置才能使用。我建议:
$output=`( echo "set heading off" ; echo "set feedback off" ; echo "set newpage none" ; echo "set pagesize 0" ; echo "select sysdate from dual;" ) | sqlplus -s $dbuser\/$dbpasswd\@$db`;
别忘了咬住结果:
chomp $output