perl执行ORACLE存储过程报错!
时间:2010-08-21
来源:互联网
本帖最后由 leoxqing 于 2010-08-21 16:54 编辑
check_oracle_tablespace.pl
#!/usr/bin/perl -w
use DBI;
use DBD::Oracle;
use File::Basename;
use Getopt::Long;
$progname=basename($0);
sub print_help();
sub print_usage();
use vars qw (
$opt_help
$opt_host
$opt_sid
$opt_user
$opt_password
);
Getopt::Long::Configure('bundling');
GetOptions (
"h" => \$opt_help, "help" => \$opt_help,
"usage" => \$opt_usage,
"H=s" => \$opt_host, "host=s" => \$opt_host,
"S=s" => \$opt_sid, "sid=s" => \$opt_sid,
"U=s" => \$opt_user, "user=s" => \$opt_user,
"P=s" => \$opt_password, "password=s" => \$opt_password
) || die "Try '$progname --help' for more information.\n";
my %ERRORS = ('OK' , 0,
'WARNING', 1,
'CRITICAL', 2,
'UNKNOWN',3);
sub print_help()
{
print "\n";
print "HELP for $progname:\n\n";
print "\t --help, -h\t\t prints this Message.\n";
print "\t --usage\t\t prints a little Usage.\n";
print "\n"; print "\t --host, -h\t\t the host for remote oracle.\n";
print "\n"; print "\t --sid, -S\t\t the SID for remote oracle.\n";
print "\n"; print "\t --user, -U\t\t the username for remote oracle.\n";
print "\n"; print "\t --password, -P\t\t the password for remote oracle.\n";
print "\n";
}
sub print_usage()
{
print "\n";
print "USAGE:\n";
print "./check_oracle_tablespace -H 127.0.0.1 -S ORCL -U username -P password\n";
print "\n";
print "Check the oracle tablespace.\n";
print "\n";
}
if ($opt_help)
{
print_help();
exit;
}
elsif ($opt_usage)
{
print_usage();
exit;
}
elsif ($opt_host && $opt_sid && $opt_user && $opt_password)
{
#my $dbname="BOSSDATA";
#my $user="sys";
#my $passwd="sjorc1";
my $dbh="";
$dbh = DBI->connect("DBI:Oracle:host=$opt_host;sid=$opt_sid",$opt_user,$opt_password)or die "can't connect to database ";
#$dbh = DBI->connect("DBI:Oracle:host=$opt_host;sid=$opt_sid",$opt_user,$opt_password,{ora_session_mode => ORA_SYSDBA}) or die "can't connect to database ";
my ($status,$msg);
my $sql1=qq{begin
pk_ocp_database_monitor.ps_tablespace_monitor(:param1,:param2);
end;};
$sth=$dbh->prepare($sql1);
$sth->bind_param_inout(":param1",\$msg,500);
$sth->bind_param_inout(":param2",\$status,2);
$sth->execute;
$dbh->disconnect;
print "Oracle Machine $opt_host check:$msg\n";
exit $status;
}
else
{
print_help();
exit;
}
写了个nagios监控插件,用perl调用ORACLE存储过程,用sysdba用户执行就正常,用oracle普通用户权限执行就报错,错误信息如下:
[root@leoxqing ~]# ./check_oracle_tablespace.pl -H 192.168.10.203 -S dfe -U ms -P rds
DBD::Oracle::st execute failed: ORA-06550: line 2, column 5:
PLS-00201: identifier 'PK_OCP_DATABASE_MONITOR.PS_TABLESPACE_MONITOR' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored (DBD ERROR: error possibly near <*> indicator at char 10 in 'begin
<*>pk_ocp_database_monitor.ps_tablespace_monitor(:param1,:param2);
end;') [for Statement "begin
pk_ocp_database_monitor.ps_tablespace_monitor(:param1,:param2);
end;" with ParamValues: :param1=undef, :param2=undef] at ./check_oracle_tablespace.pl line 76.
Use of uninitialized value in concatenation (.) or string at ./check_oracle_tablespace.pl line 78.
Oracle Machine 192.168.70.206 check:
Use of uninitialized value in exit at ./check_oracle_tablespace.pl line 79.
不知道何原因,本人对ORACLE不熟,忘大侠们指教!
check_oracle_tablespace.pl
#!/usr/bin/perl -w
use DBI;
use DBD::Oracle;
use File::Basename;
use Getopt::Long;
$progname=basename($0);
sub print_help();
sub print_usage();
use vars qw (
$opt_help
$opt_host
$opt_sid
$opt_user
$opt_password
);
Getopt::Long::Configure('bundling');
GetOptions (
"h" => \$opt_help, "help" => \$opt_help,
"usage" => \$opt_usage,
"H=s" => \$opt_host, "host=s" => \$opt_host,
"S=s" => \$opt_sid, "sid=s" => \$opt_sid,
"U=s" => \$opt_user, "user=s" => \$opt_user,
"P=s" => \$opt_password, "password=s" => \$opt_password
) || die "Try '$progname --help' for more information.\n";
my %ERRORS = ('OK' , 0,
'WARNING', 1,
'CRITICAL', 2,
'UNKNOWN',3);
sub print_help()
{
print "\n";
print "HELP for $progname:\n\n";
print "\t --help, -h\t\t prints this Message.\n";
print "\t --usage\t\t prints a little Usage.\n";
print "\n"; print "\t --host, -h\t\t the host for remote oracle.\n";
print "\n"; print "\t --sid, -S\t\t the SID for remote oracle.\n";
print "\n"; print "\t --user, -U\t\t the username for remote oracle.\n";
print "\n"; print "\t --password, -P\t\t the password for remote oracle.\n";
print "\n";
}
sub print_usage()
{
print "\n";
print "USAGE:\n";
print "./check_oracle_tablespace -H 127.0.0.1 -S ORCL -U username -P password\n";
print "\n";
print "Check the oracle tablespace.\n";
print "\n";
}
if ($opt_help)
{
print_help();
exit;
}
elsif ($opt_usage)
{
print_usage();
exit;
}
elsif ($opt_host && $opt_sid && $opt_user && $opt_password)
{
#my $dbname="BOSSDATA";
#my $user="sys";
#my $passwd="sjorc1";
my $dbh="";
$dbh = DBI->connect("DBI:Oracle:host=$opt_host;sid=$opt_sid",$opt_user,$opt_password)or die "can't connect to database ";
#$dbh = DBI->connect("DBI:Oracle:host=$opt_host;sid=$opt_sid",$opt_user,$opt_password,{ora_session_mode => ORA_SYSDBA}) or die "can't connect to database ";
my ($status,$msg);
my $sql1=qq{begin
pk_ocp_database_monitor.ps_tablespace_monitor(:param1,:param2);
end;};
$sth=$dbh->prepare($sql1);
$sth->bind_param_inout(":param1",\$msg,500);
$sth->bind_param_inout(":param2",\$status,2);
$sth->execute;
$dbh->disconnect;
print "Oracle Machine $opt_host check:$msg\n";
exit $status;
}
else
{
print_help();
exit;
}
写了个nagios监控插件,用perl调用ORACLE存储过程,用sysdba用户执行就正常,用oracle普通用户权限执行就报错,错误信息如下:
[root@leoxqing ~]# ./check_oracle_tablespace.pl -H 192.168.10.203 -S dfe -U ms -P rds
DBD::Oracle::st execute failed: ORA-06550: line 2, column 5:
PLS-00201: identifier 'PK_OCP_DATABASE_MONITOR.PS_TABLESPACE_MONITOR' must be declared
ORA-06550: line 2, column 5:
PL/SQL: Statement ignored (DBD ERROR: error possibly near <*> indicator at char 10 in 'begin
<*>pk_ocp_database_monitor.ps_tablespace_monitor(:param1,:param2);
end;') [for Statement "begin
pk_ocp_database_monitor.ps_tablespace_monitor(:param1,:param2);
end;" with ParamValues: :param1=undef, :param2=undef] at ./check_oracle_tablespace.pl line 76.
Use of uninitialized value in concatenation (.) or string at ./check_oracle_tablespace.pl line 78.
Oracle Machine 192.168.70.206 check:
Use of uninitialized value in exit at ./check_oracle_tablespace.pl line 79.
不知道何原因,本人对ORACLE不熟,忘大侠们指教!
作者: leoxqing 发布时间: 2010-08-21
回复 leoxqing
在普通用户下能手工执行pk_ocp_database_monitor.ps_tablespace_monitor这个吗?
在普通用户下能手工执行pk_ocp_database_monitor.ps_tablespace_monitor这个吗?
作者: yybmsrs 发布时间: 2010-08-23
以普通用户登录ORACLE单独执行存储过程是可以通过的!
作者: leoxqing 发布时间: 2010-08-23
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28