在 Perl 脚本中使用特殊字符

Use special character in Perl Script

我尝试执行脚本以使用 Perl 脚本从数据库中获取数据,但我的查询包含一个特殊字符,因为我在 Oracle 中获取信息表单 v$process

我使用这些行:

   my $dbh = DBI->connect ( "dbi:Oracle:$TNS", $USER, $PASS ) || die ($DBI::errstr . "\n");
    $dbh->do("ALTER SESSION SET NLS_DATE_FORMAT = 'yyyy-mm-dd hh24:mi:ss'");
    $dbh->{AutoCommit} = 0;
    $dbh->{RaiseError} = 1;
    $dbh->{ora_check_sql} = 0;
    $dbh->{RowCacheSize} = 32;
    #Sessions, Datafiles
    my $wstmt = qq{ 
    select 'PROCESOS',count(*) AS 'TOTALPROCESOS' from v$process
    };
    my $sth = $dbh->prepare( $wstmt );
    $sth->execute();
    my $ref;
    while($ref = $sth->fetchrow_arrayref) {
    print join (",", @{$ref}), "\n";
    }
    $sth->finish();
    $dbh->disconnect if defined( $dbh ); 

但是结果是

ORA-04044: procedure, function, package, or type is not allowed here (DBD ERROR: error possibly near <*> indicator at char 57 in '
    select 'PROCESOS',count(*) AS "TOTALPROCESOS" from <*>v
    ') [for Statement "
    select 'PROCESOS',count(*) AS "TOTALPROCESOS" from v

双引号运算符,如 qq,内插变量。 $process 看起来像 Perl 中的变量。如果您想要文字字符串 $process,请使用单引号运算符,例如 q:

my $wstmt = q{ 
select 'PROCESOS',count(*) AS 'TOTALPROCESOS' from v$process
};