嗨,我正在编写一个Perl脚本以使用SQL Plus连接到数据库,但是当我查询数据时,它没有显示正确的输出,有人可以解释一下。
$ perl test.pl -u用户-p paswd -d数据库
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
答案 0 :(得分:0)
我认为缺少;
$output=`echo "select sysdate from dual;" | sqlplus $dbuser\/$dbpasswd\@$db`;
答案 1 :(得分:0)
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