我有sql文件,我试图从像这样的perl脚本执行 -
my $dsn = "dbi:Oracle:$ENV{MPR_DB_INSTANCE}";
my $tg_dbh = DBI->connect($dsn,$ENV{MPR_DB_USER},$ENV{MPR_DB_PASS},{AutoCommit=>0});
unless ($tg_dbh) {&PrintAndLog("\nDBI connect failed: Unable to connect to database $tg_dbh");}
print("\nConnected to DB: $ENV{MPR_DB_USER}\@$ENV{MPR_DB_INSTANCE}\n");
print("\nRunning SQL for SY Test\n");
$sql_statement = $tg_dbh->prepare("$ENV{BIN_PATH}/SY_TG_Test.sql");
$sql_statement->execute();
$tg_dbh->commit;
我收到ORA-00900:执行无效的SQL语句。
知道我做错了什么?
答案 0 :(得分:0)
prepare
方法的参数应该是一个SQL语句(带占位符),而不是文件名。
open my $SQL, '<', "$ENV{BIN_PATH}/SY_TG_Test.sql" or die $!;
my $sql_statement = $tg_dbh->prepare(do {local $/; <$SQL>});