gpt4 book ai didi

database - 在 Perl 脚本中运行 PL/SQL 过程

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:53 24 4
gpt4 key购买 nike

我有一个 Perl 脚本,它将一个文件作为输入并在其中包含 PL/SQL(用于语句和 DBMS_OUTPUT.PUT_LINE)。我需要运行建立数据库连接并在 Perl 脚本中运行该文件。pl/sql 有开始声明结束部分,上面有 for 语句,它正在写入使用逗号分隔的 3 列数据(DBMS_OUTPUT.PUT_LINE)我已经展示了什么我在下面尝试过。是否正确?

my $dbh = DBI->connect( "dbi:Oracle:$db", $username, $passwd ) ||
die( $DBI::errstr . "\n" );
$dbh->{AutoCommit} = 0;
$dbh->{PrintError} = 1;

open FILE, $sql_file or die "Could not open file";

$query = '';
while($line = <FILE>) {
chomp($line);
$query .= $line;
}

my $sth = $dbh->prepare($query);

$sth->execute();

while ( my @row = $sth->fetchrow_array() ) {
foreach (@row) {
print "$_";
}
print "\n";
}

最佳答案

$sth->fetch()$sth->fetchrow_*() 和 friend 都从结果集中获取记录。在 Oracle PL/SQL 中, block 通常不返回结果集。所以在运行 PL/SQL block 后调用 $sth->fetchrow_array() 不会返回任何结果。

如果您使用 DBMS_OUTPUT.PUT_LINE 输出结果,您将需要使用 dbms_output_* functions provided by DBD::Oracle .

my $dbms_output_byte_limit = 1000000;
$dbh->func( $dbms_output_byte_limit, 'dbms_output_enable' );

my $sth = $dbh->prepare($query);
$sth->execute();

my @text = $dbh->func( 'dbms_output_get' );

关于database - 在 Perl 脚本中运行 PL/SQL 过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com