Database Reference
In-Depth Information
my @row=$sth->fetchrow_array;
printf "Connected as user %s.\n", $row[0];
$ chmod +x os.pl
$ ./os.pl
Connected as user OPS$ORACLE.
Connect Attributes
There are four additional attributes that may be passed to the connect method. They are
AutoCommit
,
ora_module_name
,
PrintError
, and
RaiseError
. Each is explained in detail in the
next sections, and recommendations for optimal values in conjunction with the ORACLE
DBMS are given. You may pass one or more of these attributes to the connect method, by sepa-
rating them with commas.
AutoCommit
The setting of the
AutoCommit
attribute decides whether or not each execution of an
INSERT
,
UPDATE
,
DELETE
, or
MERGE
statement is committed immediately and implicitly or explicitly at a
later time by executing
$dbh->commit
. The default setting of
AutoCommit
is
1
(enabled). Since
committing each change individually severely degrades the response time of any application,
it is imperative that
AutoCommit
is explicitly set to
0
(disabled).
Module Name
The attribute
ora_module_name
may be used to set
V$SESSION.MODULE
, which is useful for letting
the database administrator identify an application. The result of setting
ora_module_name
is the
same as if the procedure
DBMS_APPLICATION_INFO.SET_MODULE
were called in an anonymous
block, but is achieved with almost no extra coding. The default value is
perl
on UNIX and
perl.exe
on Windows. Note that module names set in this way are ignored by tracing and
client statistics functionality controlled with
DBMS_MONITOR
(see also related data dictionary
views
DBA_ENABLED_TRACES
and
DBA_ENABLED_AGGREGATIONS
).
PrintError
PrintError
controls the behavior of the Perl DBI in case of an error. The default value is
1
(enabled),
which means errors are printed on the standard error output. When
PrintError=0
is set, the
application is responsible for printing error messages when deemed appropriate. Since not all
errors may be fatal or even indicative of a problem, the recommended setting is
0
(disabled).
RaiseError
RaiseError
controls whether or not DBI raises a Perl exception whenever an error is encoun-
tered. It applies to all DBI methods except
connect
. As an alternative, the return codes of each
individual DBI call may be checked. Since it is much more convenient to embed many DBI
calls in an
eval
block that catches exceptions than coding an
if
else
sequence for each DBI call
based on the return code, using
eval
is the much preferred approach. The default value of
RaiseError
is
0
(disabled). When
RaiseError=1
(enabled) is set, exceptions are raised whenever
a DBI call fails.