📄 oracle.pm
字号:
=item ORA_OCIOracle doesn't provide a formal API for determining the exact versionnumber of the OCI client library used, so DBD::Oracle has to go digging(and sometimes has to more or less guess). The ORA_OCI constantholds the result of that process.In string context ORA_OCI returns the full "A.B.C.D" version string.In numeric context ORA_OCI returns the major.minor version number(8.1, 9.2, 10.0 etc). But note that version numbers are not actuallyfloating point and so if Oracle ever makes a release that has a twodigit minor version, such as C<9.10> it will have a lower numericvalue than the preceding C<9.9> release. So use with care.The contents and format of ORA_OCI are subject to change (it may,for example, become a I<version object> in later releases).I recommend that you avoid checking for exact values.=head2 Connect Attributes=over 4=item ora_session_modeThe ora_session_mode attribute can be used to connect with SYSDBAauthorization and SYSOPER authorization.The ORA_SYSDBA and ORA_SYSOPER constants can be imported using use DBD::Oracle qw(:ora_session_modes);This is one case where setting ORACLE_SID may be useful sinceconnecting as SYSDBA or SYSOPER via SQL*Net is frequently disabledfor security reasons.Example: $dsn = "dbi:Oracle:"; # no dbname here $ENV{ORACLE_SID} = "orcl"; # set ORACLE_SID as needed delete $ENV{TWO_TASK}; # make sure TWO_TASK isn't set $dbh = DBI->connect($dsn, "", "", { ora_session_mode => ORA_SYSDBA });It has been reported that this only works if $dsn does not contain a SIDso that Oracle then uses the value of the ORACLE_SID (not TWO_TASK)environment variable to connect to a local instance. Also the usernameand password should be empty, and the user executing the script needsto be part of the dba group or osdba group.=item ora_oratab_orahomePassing a true value for the ora_oratab_orahome attribute will makeDBD::Oracle change $ENV{ORACLE_HOME} to make the Oracle home directoryspecified in the C</etc/oratab> file I<if> the database to connect tois specified as a SID that exists in the oratab file, and DBD::Oracle wasbuilt to use the Oracle 7 OCI API (not Oracle 8+).=item ora_module_nameAfter connecting to the database the value of this attribute is passedto the SET_MODULE() function in the C<DBMS_APPLICATION_INFO> PL/SQLpackage. This can be used to identify the application to the DBA formonitoring and performance tuning purposes. For example: DBI->connect($dsn, $user, $passwd, { ora_module_name => $0 });=item ora_dbh_shareNeeds at least Perl 5.8.0 compiled with ithreads. Allows to share databaseconnections between threads. The first connect will make the connection, all following calls to connect with the same ora_dbh_share attributewill use the same database connection. The value must be a referenceto a already shared scalar which is initialized to an empty string. our $orashr : shared = '' ; $dbh = DBI->connect ($dsn, $user, $passwd, {ora_dbh_share => \$orashr}) ;=item ora_use_proc_connectionThis attribute allows to create a DBI handle for an existing SQLLIBdatabase connection. This can be used to share database connectionsbetween Oracle ProC code and DBI running in an embedded Perl interpreter.The SQLLIB connection id is appended after the "dbi:Oracle:" initialargument to DBI::connect.For example, if in ProC a connection is made like EXEC SQL CONNECT 'user/pass@db' AT 'CONID';the connection may be used from DBI after running something like my $dbh = DBI->connect("dbi:Oracle:CONID", "", "", { ora_use_proc_connection => 1 });To disconnect, first call $dbh->disconnect(), then disconnect in ProC.This attribute requires DBD::Oracle to be built with the -ProCoption to Makefile.PL. It is not available with OCI_V7. Not testedwith Perl ithreads or with the ora_dbh_share connect attribute.=item ora_envhpThe first time a connection is made a new OCI 'environment' iscreated by DBD::Oracle and stored in the driver handle.Subsequent connects reuse (share) that same OCI environmentby default.The ora_envhp attribute can be used to disable the reuse of the OCIenvironment from a previous connect. If the value is C<0> thena new OCI environment is allocated and used for this connection.The OCI environment is what holds information about the client sidecontext, such as the local NLS environment. So by altering %ENV andsetting ora_envhp to 0 you can create connections with differentNLS settings. This is most useful for testing.=item ora_charset, ora_ncharsetFor oracle versions >= 9.2 you can specify the client charset andncharset with the ora_charset and ora_ncharset attributes. Youstill need to pass C<ora_envhp = 0> for all but the first connect.These attributes override the settings from environment variables. $dbh = DBI->connect ($dsn, $user, $passwd, {ora_charset => 'AL32UTF8'});=back=head2 Database Handle Attributes=over 4=item C<ora_ph_type>The default placeholder data type for the database session.The C<TYPE> or L</ora_type> attributes to L<DBI/bind_param> andL<DBI/bind_param_inout> override the data type for individual placeholders.The most frequent reason for using this attribute is to permit trailing spacesin values passed by placeholders.Constants for the values allowed for this attribute can be imported using use DBD::Oracle qw(:ora_types);Only the following values are permitted for this attribute.=over 4=item ORA_VARCHAR2Oracle clients using OCI 8 will strip trailing spaces and allow embedded \0 bytes.Oracle clients using OCI 9.2 do not strip trailing spaces and allow embedded \0 bytes.This is the normal default placeholder type.=item ORA_STRINGDon't strip trailing spaces and end the string at the first \0.=item ORA_CHARDon't strip trailing spaces and allow embedded \0.Force 'blank-padded comparison semantics'.For example: use DBD::Oracle qw(:ora_types); $sql="select username from all_users where username = ?"; #username is a char(8) $sth=$dbh->prepare($sql)"; $sth->bind_param(1,'bloggs',{ ora_type => ORA_CHAR}); Will pad bloggs out to 8 chracters and return the username. =back=item ora_parse_error_offsetIf the previous error was from a failed C<prepare> due to a syntax error,this attribute gives the offset into the C<Statement> attribute where theerror was found.=back=over 4=item ora_array_chunk_sizeBecause of OCI limitations, DBD::Oracle needs to buffer up rows ofbind values in its C<execute_for_fetch> implementation. This attributesets the number of rows to buffer at a time (default value is 1000).The C<execute_for_fetch> function will collect (at most) this manyrows in an array, send them of to the DB for execution, then go backto collect the next chunk of rows and so on. This attribute can beused to limit or extend the number of rows processed at a time.Note that this attribute also applies to C<execute_array>, since thatmethod is implemented using C<execute_for_fetch>.=back=head2 Prepare AttributesThese attributes may be used in the C<\%attr> parameter of theL<DBI/prepare> database handle method.=over 4=item ora_placeholdersSet to false to disable processing of placeholders. Used mainly for loading aPL/SQL package that has been I<wrapped> with Oracle's C<wrap> utility.=item ora_parse_langTells the connected database how to interpret the SQL statement.If 1 (default), the native SQL version for the database is used.Other recognized values are 0 (old V6, treated as V7 in OCI8),2 (old V7), 7 (V7), and 8 (V8).All other values have the same effect as 1.=item ora_auto_lobIf true (the default), fetching retrieves the contents of the CLOB orBLOB column in most circumstances. If false, fetching retrieves theOracle "LOB Locator" of the CLOB or BLOB value.See L</Handling LOBs> for more details.See also the LOB tests in 05dbi.t of Oracle::OCI for examplesof how to use LOB Locators.=item ora_check_sqlIf 1 (default), force SELECT statements to be described in prepare().If 0, allow SELECT statements to defer describe until execute().See L</Prepare postponed till execute> for more information.=back=head2 Placeholder Binding AttributesThese attributes may be used in the C<\%attr> parameter of theL<DBI/bind_param> or L<DBI/bind_param_inout> statement handle methods.=over 4=item ora_typeSpecify the placeholder's data type using an Oracle data type.A fatal error is raised if C<ora_type> and the DBI C<TYPE> attributeare used for the same placeholder.Some of these types are not supported by the current version ofDBD::Oracle and will cause a fatal error if used.Constants for the Oracle datatypes may be imported using use DBD::Oracle qw(:ora_types);Potentially useful values when DBD::Oracle was built using OCI 7 and later: ORA_VARCHAR2, ORA_STRING, ORA_LONG, ORA_RAW, ORA_LONGRAW, ORA_CHAR, ORA_MLSLABEL, ORA_RSETAdditional values when DBD::Oracle was built using OCI 8 and later: ORA_CLOB, ORA_BLOB, ORA_NTY, ORA_VARCHAR2_TABLE, ORA_NUMBER_TABLESee L</Binding Cursors> for the correct way to use ORA_RSET.See L</Handling LOBs> for how to use ORA_CLOB and ORA_BLOB.See L</SYS.DBMS_SQL datatypes> for ORA_VARCHAR2_TABLE, ORA_NUMBER_TABLE.See L</Other Data Types> for more information.See also L<DBI/Placeholders and Bind Values>.=item ora_csformSpecify the OCI_ATTR_CHARSET_FORM for the bind value. Valid valuesare SQLCS_IMPLICIT (1) and SQLCS_NCHAR (2). Both those constants canbe imported from the DBD::Oracle module. Rarely needed.=item ora_csidSpecify the I<integer> OCI_ATTR_CHARSET_ID for the bind value. Character set names can't be used currently.=item ora_maxdata_sizeSpecify the integer OCI_ATTR_MAXDATA_SIZE for the bind value. May be needed if a character set conversion from client to servercauses the data to use more space and so fail with a truncation error.=item ora_maxarray_numentriesSpecify the maximum number of array entries to allocate. Used withORA_VARCHAR2_TABLE, ORA_NUMBER_TABLE. Define the maximum number ofarray entries Oracle can pass back to you in OUT variable of typeTABLE OF ... .=item ora_internal_typeSpecify internal data representation. Currently is supported only forORA_NUMBER_TABLE.=back=head2 Trailing SpacesPlease note that only the Oracle OCI 8 strips trailing spaces from VARCHAR placeholdervalues and uses Nonpadded Comparison Semantics with the result. This causes trouble if the spaces are needed forcomparison with a CHAR value or to prevent the value frombecoming '' which Oracle treats as NULL.Look for Blank-padded Comparison Semantics and NonpaddedComparison Semantics in Oracle's SQL Reference or ServerSQL Reference for more details.To preserve trailing spaces in placeholder values for Oracle clients that use OCI 8, either change the default placeholder type with L</ora_ph_type> or the placeholdertype for a particular call to L<DBI/bind> or L<DBI/bind_param_inout>with L</ora_type> or C<TYPE>.Using L<ORA_CHAR> with L<ora_type> or C<SQL_CHAR> with C<TYPE>allows the placeholder to be used with Padded Comparison Semanticsif the value it is being compared to is a CHAR, NCHAR, or literal.Please remember that using spaces as a value or at the end ofa value makes visually distinguishing values with differentnumbers of spaces difficult and should be avoided.Oracle Clients that use OCI 9.2 do not strip trailing spaces.=head2 Padded Char FieldsOracle Clients after OCI 9.2 will automatically pad CHAR placeholder values to the size of the CHAR.As the default placeholder type value in DBD::Oracle is ORA_VARCHAR2 to access this behavior you will have to change the default placeholder type with L</ora_ph_type> or placeholder type for a particular call with L<DBI/bind> or L<DBI/bind_param_inout>with L</ORA_CHAR> or C<ORA_CHARZ>.=head1 Metadata=head2 C<get_info()>DBD::Oracle supports C<get_info()>, but (currently) only a few info types.=head2 C<table_info()>DBD::Oracle supports attributes for C<table_info()>.In Oracle, the concept of I<user> and I<schema> is (currently) thesame. Because database objects are owned by an user, the owner namesin the data dictionary views correspond to schema names.Oracle does not support catalogs so TABLE_CAT is ignored asselection criterion.Search patterns are supported for TABLE_SCHEM and TABLE_NAME.TABLE_TYPE may contain a comma-separated list of table types.The following table types are supported: TABLE VIEW SYNONYM SEQUENCEThe result set is ordered by TABLE_TYPE, TABLE_SCHEM, TABLE_NAME.The special enumerations of catalogs, schemas and table types aresupported. However, TABLE_CAT is always NULL.An identifier is passed I<as is>, i.e. as the user provides orOracle returns it.C<table_info()> performs a case-sensitive search. So, a selectioncriterion should respect upper and lower case.Normally, an identifier is case-insensitive. Oracle stores andreturns it in upper case. Sometimes, database objects are createdwith quoted identifiers (for reserved words, mixed case, specialcharacters, ...). Such an identifier is case-sensitive (if not allupper case). Oracle stores and returns it as given.C<table_info()> has no special quote handling, neither adds norremoves quotes.=head2 C<primary_key_info()>Oracle does not support catalogs so TABLE_CAT is ignored asselection criterion.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -