在Perl脚本中运行select语句时需要帮助

时间:2018-10-17 08:04:14

标签: windows perl

$START_PRI_AA=1;

$expression = "$SQLPLUS_DIR\\$SQLPLUS_EXEC -S $PLANSTAGE_DB_USER/$PLANSTAGE_DB_PASSWORD\@$PLANSTAGE_DB_ALIAS  
        'set pagesize 0
        set feedback off
        set verify off
        set heading off
        set echo off 
        select STATUS from jdaabppd.DFXHA_ENGINE_STATUS where ENGINE_NAME ='$ENV{PRI_AA_ENGINE}';
        exit;
        /'
        ";

print "\n\n expression is $expression \n\n";
$status = system($expression);

print "$status\n\n";

1 个答案:

答案 0 :(得分:0)

为什么要在Perl中使用SQLPLUS,而它已经具有与数据库交互的出色模块?

首先,您需要安装模块DBIDBD::Oracle,然后可以执行以下操作:

use strict;
use warnings;
use DBI;

my $dbh = DBI->connect(
    "dbi:Oracle:host=locahost;port=1521;sid=$PLANSTAGE_DB_ALIAS",  # DSN of the database to connect 
    $PLANSTAGE_DB_USER,      # username
    $PLANSTAGE_DB_PASSWORD,  # password
    { RaiseError => 1 }      # die on any DBI error
);

my ($status) = $dbh->selectrow_array(
    "select STATUS from jdaabppd.DFXHA_ENGINE_STATUS where ENGINE_NAME ='?", # your sql query
    undef,                 # no specific options needed 
    $ENV{PRI_AA_ENGINE}    # bind value
);

您可能需要根据您的用例调整DSN,我根据您显示的代码段做出了一些假设。阅读DBI文档以获得更多详细信息。