Perl 脚本无法从 linux shell 连接到 Oracle,并显示错误和代码

发布于 2024-11-14 15:37:11 字数 1714 浏览 3 评论 0原文

我需要一些帮助来确定从 perl 文件到数据库的连接问题。

当从网络(浏览器到 /file.pl url)运行时,代码可以正常运行和执行。

在 shell 上下文(putty)中,当我运行脚本“perl /file.pl”时,出现此错误:

[date] file.pl: DBI connect('address','username', 'password') failed: 
ERROR OCIEnvNlsCreate (check OR ACLE_HOME and NLS settings etc.) at file.pl line 61

第 61 行显示:

$dbh = DBI->connect(A, B, C );

更多详细信息:当另一个用户(可能具有更多权限)运行该文件时,它对他有效(在外壳中)。

#!/usr/bin/perl -w

require 'include.pl';
require 'bencfg.pl';
use lib '/www/modules/'; #rqd
use DBI;
use DBD::Oracle;

print "Content-type: text/html; charset=UTF-8\n\n";
print "Test Run of connection...\n\n<br>";
print "ORA_HOME: '$ENV{ORACLE_HOME}'\n<br>";  #ORA_HOME: '/opt/oracle/10g/'

#connect to DB
$dbh = DBI->connect(A, B C) || die "Database connection not made: $DBI::errstr";
if($dbh){
   print "OK\n<br>";
   $dbh->disconnect;
}
else{
   print "failed: $DBI::errstr\n";
 }

我知道 DBI->connect 工作的变量。那不是问题。我相信它的权限,但我不知道如何修复它。

一些附加信息: ORA_HOME: '/opt/oracle/10g'

NLS_SESSION_PARAMETERS

    PARAMETER   VALUE
    NLS_LANGUAGE    AMERICAN
    NLS_TERRITORY   AMERICA
    NLS_CURRENCY    $
    NLS_ISO_CURRENCY    AMERICA
    NLS_NUMERIC_CHARACTERS  .,
    NLS_CALENDAR    GREGORIAN
    NLS_DATE_FORMAT MM/DD/YYYY HH24:MI:SS
    NLS_DATE_LANGUAGE   AMERICAN
    NLS_SORT    BINARY
    NLS_TIME_FORMAT HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT    DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT  HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY   $
NLS_COMP    BINARY
NLS_LENGTH_SEMANTICS    BYTE
NLS_NCHAR_CONV_EXCP FALSE

I need some help in determining the problem with my connection from a perl file to a DB.

The code runs and executes fine when it is run from the web (browser to /file.pl url).

In a shell context (putty), when I run the script "perl /file.pl", I get this error:

[date] file.pl: DBI connect('address','username', 'password') failed: 
ERROR OCIEnvNlsCreate (check OR ACLE_HOME and NLS settings etc.) at file.pl line 61

Line 61 reads:

$dbh = DBI->connect(A, B, C );

More details: When another user (with presumably more permissions) runs the file, it works for him (in the shell).

#!/usr/bin/perl -w

require 'include.pl';
require 'bencfg.pl';
use lib '/www/modules/'; #rqd
use DBI;
use DBD::Oracle;

print "Content-type: text/html; charset=UTF-8\n\n";
print "Test Run of connection...\n\n<br>";
print "ORA_HOME: '$ENV{ORACLE_HOME}'\n<br>";  #ORA_HOME: '/opt/oracle/10g/'

#connect to DB
$dbh = DBI->connect(A, B C) || die "Database connection not made: $DBI::errstr";
if($dbh){
   print "OK\n<br>";
   $dbh->disconnect;
}
else{
   print "failed: $DBI::errstr\n";
 }

I know the variables of DBI->connect work. Thats not the issue. I believe its permissions but I cant tell how to fix it.

Some additional info:
ORA_HOME: '/opt/oracle/10g'

NLS_SESSION_PARAMETERS

    PARAMETER   VALUE
    NLS_LANGUAGE    AMERICAN
    NLS_TERRITORY   AMERICA
    NLS_CURRENCY    $
    NLS_ISO_CURRENCY    AMERICA
    NLS_NUMERIC_CHARACTERS  .,
    NLS_CALENDAR    GREGORIAN
    NLS_DATE_FORMAT MM/DD/YYYY HH24:MI:SS
    NLS_DATE_LANGUAGE   AMERICAN
    NLS_SORT    BINARY
    NLS_TIME_FORMAT HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT    DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT  HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY   $
NLS_COMP    BINARY
NLS_LENGTH_SEMANTICS    BYTE
NLS_NCHAR_CONV_EXCP FALSE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不交电费瞎发啥光 2024-11-21 15:37:11

每次我在连接到 10g 时遇到此问题时,我都必须确保设置了 NLS_LANG env var:

## for utf8 data
$ENV{NLS_LANG} = 'american_america.al32utf8';
## for ios-8859-1 data
$ENV{NLS_LANG} = 'american_america.we8iso8859p1';  

另外,将 ORA_NLS 设置为 nls 文件的路径

$ENV{ORA_NLS} = -d "$ENV{ORACLE_HOME}/ocommon/nls/admin/data" ? "$ENV{ORACLE_HOME}/ocommon/nls/admin/data" : 
   -d "$ENV{ORACLE_HOME}/nls/admin/data" ? "$ENV{ORACLE_HOME}/nls/admin/data" : 
   -d "$ENV{ORACLE_HOME}/nls/data" ? "$ENV{ORACLE_HOME}/nls/data"

$ENV{ ORA_NLS32 }     = $ENV{ORACLE_NLS};

Re: 更多详细信息: ... 当另一个用户 ...运行该文件,它对他有用

尝试转储该用户的环境设置,

env|grep NLS

Every time I've had this issue with connecting to 10g, I had to make sure NLS_LANG env var was set:

## for utf8 data
$ENV{NLS_LANG} = 'american_america.al32utf8';
## for ios-8859-1 data
$ENV{NLS_LANG} = 'american_america.we8iso8859p1';  

Plus, set ORA_NLS to path of nls files

$ENV{ORA_NLS} = -d "$ENV{ORACLE_HOME}/ocommon/nls/admin/data" ? "$ENV{ORACLE_HOME}/ocommon/nls/admin/data" : 
   -d "$ENV{ORACLE_HOME}/nls/admin/data" ? "$ENV{ORACLE_HOME}/nls/admin/data" : 
   -d "$ENV{ORACLE_HOME}/nls/data" ? "$ENV{ORACLE_HOME}/nls/data"

$ENV{ ORA_NLS32 }     = $ENV{ORACLE_NLS};

Re: More details: ... When another user ... runs the file, it works for him

Try dumping that user's env settings,

env|grep NLS
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文