大家好,请帮助我了解如何从perl脚本调用pl sql文件
我有一个像这样的pl sql文件
DECLARE
x NUMBER := 100;
BEGIN
FOR i IN 1..10 LOOP
IF MOD(i,2) = 0 THEN -- i is even
INSERT INTO temp VALUES (i, x, 'i is even');
ELSE
INSERT INTO temp VALUES (i, x, 'i is odd');
END IF;
x := x + 100;
END LOOP;
COMMIT;
END;
该文件名为test.sql我想从perl脚本调用此文件。我知道首先我们必须连接到db然后执行该过程,但我现在知道如何从perl脚本执行此文件
答案 0 :(得分:1)
基本上你需要
这是一个例子(我没有展示如何在脚本中啜食):
use DBI;
use DBD::Oracle;
my $service="xxx";
my $user = "yyy";
my $pass = "zzz";
my $DBH = DBI->connect
(
"dbi:Oracle:$service",
"$user", "$pass",
{
RaiseError => 0,
PrintError => 0,
AutoCommit => 0,
ShowErrorStatement => 0
}
) or die;
my $script = qq(
declare
x number := 1;
begin
insert into xxx values (x);
commit;
end;
);
my $sth = $DBH->prepare($script) or die;
$sth->execute() or die;
$DBH->disconnect();