home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>DBD::Oracle - Oracle database driver for the DBI module</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> DBD::Oracle - Oracle database driver for the DBI module</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#connecting to oracle">CONNECTING TO ORACLE</A></LI>
- <UL>
-
- <LI><A HREF="#connecting without environment variables or tnsname.ora file">Connecting without environment variables or tnsname.ora file</A></LI>
- <LI><A HREF="#oracle environment variables">Oracle environment variables</A></LI>
- <LI><A HREF="#connection examples using dbd::oracle">Connection Examples Using DBD::Oracle</A></LI>
- <LI><A HREF="#optimizing oracle's listner">Optimizing Oracle's listner</A></LI>
- <LI><A HREF="#oracle utilities">Oracle utilities</A></LI>
- <LI><A HREF="#connect attributes">Connect Attributes</A></LI>
- </UL>
-
- <LI><A HREF="#international nls / 8bit text issues">International NLS / 8-bit text issues</A></LI>
- <LI><A HREF="#pl/sql examples">PL/SQL Examples</A></LI>
- <LI><A HREF="#private database handle functions">Private database handle functions</A></LI>
- <UL>
-
- <LI><A HREF="#plsql_errstr">plsql_errstr</A></LI>
- <LI><A HREF="#dbms_output_enable / dbms_output_put / dbms_output_get">dbms_output_enable / dbms_output_put / dbms_output_get</A></LI>
- </UL>
-
- <LI><A HREF="#using dbd::oracle with oracle 8 features and issues">Using DBD::Oracle with Oracle 8 - Features and Issues</A></LI>
- <UL>
-
- <LI><A HREF="#prepare postponed till execute">Prepare postponed till execute</A></LI>
- <LI><A HREF="#handling lobs">Handling LOBs</A></LI>
- <LI><A HREF="#binding cursors">Binding Cursors</A></LI>
- </UL>
-
- <LI><A HREF="#oracle related links">Oracle Related Links</A></LI>
- <UL>
-
- <LI><A HREF="#oracle on linux">Oracle on Linux</A></LI>
- <LI><A HREF="#free oracle tools and links">Free Oracle Tools and Links</A></LI>
- <LI><A HREF="#commercial oracle tools and links">Commercial Oracle Tools and Links</A></LI>
- </UL>
-
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- <LI><A HREF="#acknowledgements">ACKNOWLEDGEMENTS</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>DBD::Oracle - Oracle database driver for the DBI module</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use DBI;</PRE>
- <PRE>
- $dbh = DBI->connect("dbi:Oracle:$dbname", $user, $passwd);</PRE>
- <PRE>
- $dbh = DBI->connect("dbi:Oracle:host=$host;sid=$sid", $user, $passwd);</PRE>
- <PRE>
- # See the DBI module documentation for full details</PRE>
- <PRE>
- # for some advanced uses you may need Oracle type values:
- use DBD::Oracle qw(:ora_types);</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>DBD::Oracle is a Perl module which works with the DBI module to provide
- access to Oracle databases (both version 7 and 8).</P>
- <P>
- <HR>
- <H1><A NAME="connecting to oracle">CONNECTING TO ORACLE</A></H1>
- <P>This is a topic which often causes problems. Mainly due to Oracle's many
- and sometimes complex ways of specifying and connecting to databases.
- (James Taylor and Lane Sharman have contributed much of the text in
- this section.)</P>
- <P>
- <H2><A NAME="connecting without environment variables or tnsname.ora file">Connecting without environment variables or tnsname.ora file</A></H2>
- <P>If you use the <CODE>host=$host;sid=$sid</CODE> style syntax, for example:</P>
- <PRE>
- $dbh = DBI->connect("dbi:Oracle:host=myhost.com;sid=ORCL", $user, $passwd);</PRE>
- <P>then DBD::Oracle will construct a full connection descriptor string
- for you and Oracle will not need to consult the tnsname.ora file.
- If a <CODE>port</CODE> number is not specified then the descriptor try
- both 1526 and 1521 in that order.</P>
- <P>
- <H2><A NAME="oracle environment variables">Oracle environment variables</A></H2>
- <P>Oracle typically uses two environment variables to specify default
- connections: ORACLE_SID and TWO_TASK.</P>
- <P>ORACLE_SID is really unnecessary to set since TWO_TASK provides the
- same functionality in addition to allowing remote connections.</P>
- <PRE>
- % setenv TWO_TASK T:hostname:ORACLE_SID # for csh shell
- $ TWO_TASK=T:hostname:ORACLE_SID export TWO_TASK # for sh shell</PRE>
- <PRE>
- % sqlplus username/password</PRE>
- <P>Note that if you have *both* local and remote databases, and you
- have ORACLE_SID *and* TWO_TASK set, and you don't specify a fully
- qualified connect string on the command line, TWO_TASK takes precedence
- over ORACLE_SID (i.e. you get connected to remote system).</P>
- <PRE>
- TWO_TASK=P:sid</PRE>
- <P>will use the pipe driver for local connections using SQL*Net v1.</P>
- <PRE>
- TWO_TASK=T:machine:sid</PRE>
- <P>will use TCP/IP (or D for DECNET, etc.) for remote SQL*Net v1 connection.</P>
- <PRE>
- TWO_TASK=dbname</PRE>
- <P>will use the info stored in the SQL*Net v2 <EM>tnsnames.ora</EM>
- configuration file for local or remote connections.</P>
- <P>The ORACLE_HOME environment variable should be set correctly. It can be
- left unset if you aren't using any of Oracle's executables, but it is
- not recommended and error messages may not display.</P>
- <P>Discouraging the use of ORACLE_SID makes it easier on the users to see
- what is going on. (It's unfortunate that TWO_TASK couldn't be renamed,
- since it makes no sense to the end user, and doesn't have the ORACLE
- prefix).</P>
- <P>
- <H2><A NAME="connection examples using dbd::oracle">Connection Examples Using DBD::Oracle</A></H2>
- <P>Below are various ways of connecting to an oracle database using
- SQL*Net 1.x and SQL*Net 2.x. ``Machine'' is the computer the database is
- running on, ``SID'' is the SID of the database, ``DB'' is the SQL*Net 2.x
- connection descriptor for the database.</P>
- <P><STRONG>Note:</STRONG> Some of these formats may not work with Oracle 8.</P>
- <PRE>
- BEGIN {
- $ENV{ORACLE_HOME} = '/home/oracle/product/7.x.x';
- $ENV{TWO_TASK} = 'DB';
- }
- $dbh = DBI->connect('dbi:Oracle:','scott', 'tiger');
- # - or -
- $dbh = DBI->connect('dbi:Oracle:','scott/tiger');</PRE>
- <P>works for SQL*Net 2.x, so does</P>
- <PRE>
- $ENV{TWO_TASK} = 'T:Machine:SID';</PRE>
- <P>for SQL*Net 1.x connections. For local connections you can use the
- pipe driver:</P>
- <PRE>
- $ENV{TWO_TASK} = 'P:SID';</PRE>
- <P>Here are some variations (not setting TWO_TASK)</P>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:T:Machine:SID','username','password')</PRE>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:','username@T:Machine:SID','password')</PRE>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:','username@DB','password')</PRE>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:DB','username','password')</PRE>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:DB','username/password','')</PRE>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:host=foobar;sid=ORCL;port=1521', 'scott/tiger', '')</PRE>
- <PRE>
- $dbh = DBI->connect('dbi:Oracle:', q{scott/tiger@(DESCRIPTION=
- (ADDRESS=(PROTOCOL=TCP)(HOST= foobar)(PORT=1521))
- (CONNECT_DATA=(SID=ORCL)))}, "")</PRE>
- <P>If you are having problems with login taking a long time (>10 secs say)
- then you might have tripped up on an Oracle bug. You can try using one
- of the ...@DB variants as a workaround. E.g.,</P>
- <PRE>
- $dbh = DBI->connect('','username/password@DB','');</PRE>
- <P>On the other hand, that may cause you to trip up on another Oracle bug
- that causes alternating connection attempts to fail! (In reality only
- a small proportion of people experience these problems.)</P>
- <P>
- <H2><A NAME="optimizing oracle's listner">Optimizing Oracle's listner</A></H2>
- <P>[By Lane Sharman <<A HREF="mailto:lane@bienlogic.com">lane@bienlogic.com</A>>] I spent a LOT of time optimizing
- listener.ora and I am including it here for anyone to benefit from. My
- connections over tnslistener on the same humble Netra 1 take an average
- of 10-20 milli seconds according to tnsping. If anyone knows how to
- make it better, please let me know!</P>
- <PRE>
- LISTENER =
- (ADDRESS_LIST =
- (ADDRESS =
- (PROTOCOL = TCP)
- (Host = aa.bbb.cc.d)
- (Port = 1521)
- (QUEUESIZE=10)
- )
- )</PRE>
- <PRE>
- STARTUP_WAIT_TIME_LISTENER = 0
- CONNECT_TIMEOUT_LISTENER = 10
- TRACE_LEVEL_LISTENER = OFF
- SID_LIST_LISTENER =
- (SID_LIST =
- (SID_DESC =
- (SID_NAME = xxxx)
- (ORACLE_HOME = /xxx/local/oracle7-3)
- (PRESPAWN_MAX = 40)
- (PRESPAWN_LIST=
- (PRESPAWN_DESC=(PROTOCOL=tcp) (POOL_SIZE=40) (TIMEOUT=120))
- )
- )
- )</PRE>
- <P>1) When the application is co-located on the host AND there is no need for
- outside SQLNet connectivity, stop the listener. You do not need it. Get
- your application/cgi/whatever working using pipes and shared memory. I am
- convinced that this is one of the connection bugs (sockets over the same
- machine). Note the $ENV{ORAPIPES} env var. The essential code to do
- this at the end of this section.</P>
- <P>2) Be careful in how you implement the multi-threaded server. Currently I
- am not using it in the initxxxx.ora file but will be doing some more testing.</P>
- <P>3) Be sure to create user rollback segments and use them; do not use the
- system rollback segments; however, you must also create a small rollback
- space for the system as well.</P>
- <P>5) Use large tuning settings and get lots of RAM. Check out all the
- parameters you can set in v$parameters because there are quite a few not
- documented you may to set in your initxxx.ora file.</P>
- <P>6) Use svrmgrl to control oracle from the command line. Write lots of small
- SQL scripts to get at V$ info.</P>
- <PRE>
- use DBI;
- # Environmental variables used by Oracle
- $ENV{ORACLE_SID} = "xxx";
- $ENV{ORACLE_HOME} = "/opt/oracle7";
- $ENV{EPC_DISABLED} = "TRUE";
- $ENV{ORAPIPES} = "V2";
- my $dbname = "xxx";
- my $dbuser = "xxx";
- my $dbpass = "xxx";
- my $dbh = DBI->connect("dbi:Oracle:$dbname", $dbuser, $dbpass)
- || die "Unale to connect to $dbname: $DBI::errstr\n";</PRE>
- <P>
- <H2><A NAME="oracle utilities">Oracle utilities</A></H2>
- <P>If you are still having problems connecting then the Oracle adapters
- utility may offer some help. Run these two commands:</P>
- <PRE>
- $ORACLE_HOME/bin/adapters
- $ORACLE_HOME/bin/adapters $ORACLE_HOME/bin/sqlplus</PRE>
- <P>and check the output. The ``Protocol Adapters'' section should be the
- same. It should include at least ``IPC Protocol Adapter'' and ``TCP/IP
- Protocol Adapter''.</P>
- <P>If it generates any errors which look relevant then please talk to yor
- Oracle technical support (and not the dbi-users mailing list). Thanks.
- Thanks to Mark Dedlow for this information.</P>
- <P>
- <H2><A NAME="connect attributes">Connect Attributes</A></H2>
- <P>The ora_session_mode attribute can be used to connect with SYSDBA
- authorization and SYSOPER authorization.</P>
- <PRE>
- $mode = 2; # SYSDBA
- $mode = 4; # SYSOPER
- DBI->connect($dsn, $user, $passwd, { ora_session_mode => $mode });</PRE>
- <P>
- <HR>
- <H1><A NAME="international nls / 8bit text issues">International NLS / 8-bit text issues</A></H1>
- <P>If 8-bit text is returned as '?' characters or can't be inserted
- make sure the following environment vaiables are set correctly:
- NLS_LANG, ORA_NLS, ORA_NLS32, ORA_NLS33
- Thanks to Robin Langdon <<A HREF="mailto:robin@igis.se">robin@igis.se</A>> for this information.
- Example:
- $ENV{NLS_LANG} = ``american_america.we8iso8859p1'';
- $ENV{ORA_NLS} = ``$ENV{ORACLE_HOME}/ocommon/nls/admin/data'';</P>
- <P>Also From: Yngvi Thor Sigurjonsson <<A HREF="mailto:yngvi@hagkaup.is">yngvi@hagkaup.is</A>>
- If you are using 8-bit characters and ``export'' for backups make sure
- that you have NLS_LANG set when export is run. Otherwise you might get
- unusable backups with ? replacing all your beloved characters. We were
- lucky once when we noticed that our exports were damaged before
- disaster struck.</P>
- <P>Remember that the database has to be created with an 8-bit character set.</P>
- <P>Also note that the NLS files $ORACLE_HOME/ocommon/nls/admin/data
- changed extension (from .d to .nlb) between 7.2.3 and 7.3.2.</P>
- <P>
- <HR>
- <H1><A NAME="pl/sql examples">PL/SQL Examples</A></H1>
- <P>These PL/SQL examples come from: Eric Bartley <<A HREF="mailto:bartley@cc.purdue.edu">bartley@cc.purdue.edu</A>>.</P>
- <PRE>
- # we assume this package already exists
- my $plsql = q{</PRE>
- <PRE>
- CREATE OR REPLACE PACKAGE plsql_example
- IS
- PROCEDURE proc_np;</PRE>
- <PRE>
- PROCEDURE proc_in (
- err_code IN NUMBER
- );</PRE>
- <PRE>
- PROCEDURE proc_in_inout (
- test_num IN NUMBER,
- is_odd IN OUT NUMBER
- );</PRE>
- <PRE>
- FUNCTION func_np
- RETURN VARCHAR2;</PRE>
- <PRE>
- END plsql_example;</PRE>
- <PRE>
- CREATE OR REPLACE PACKAGE BODY plsql_example
- IS
- PROCEDURE proc_np
- IS
- whoami VARCHAR2(20) := NULL;
- BEGIN
- SELECT USER INTO whoami FROM DUAL;
- END;</PRE>
- <PRE>
- PROCEDURE proc_in (
- err_code IN NUMBER
- )
- IS
- BEGIN
- RAISE_APPLICATION_ERROR(err_code, 'This is a test.');
- END;</PRE>
- <PRE>
- PROCEDURE proc_in_inout (
- test_num IN NUMBER,
- is_odd IN OUT NUMBER
- )
- IS
- BEGIN
- is_odd := MOD(test_num, 2);
- END;</PRE>
- <PRE>
- FUNCTION func_np
- RETURN VARCHAR2
- IS
- ret_val VARCHAR2(20);
- BEGIN
- SELECT USER INTO ret_val FROM DUAL;
- RETURN ret_val;
- END;</PRE>
- <PRE>
- END plsql_example;
- };</PRE>
- <PRE>
- use DBI;</PRE>
- <PRE>
- my($db, $csr, $ret_val);</PRE>
- <PRE>
- $db = DBI->connect('dbi:Oracle:database','user','password')
- or die "Unable to connect: $DBI::errstr";</PRE>
- <PRE>
- # So we don't have to check every DBI call we set RaiseError.
- # See the DBI docs now if you're not familiar with RaiseError.
- $db->{RaiseError} = 1;</PRE>
- <PRE>
- # Example 1
- #
- # Calling a PLSQL procedure that takes no parameters. This shows you the
- # basic's of what you need to execute a PLSQL procedure. Just wrap your
- # procedure call in a BEGIN END; block just like you'd do in SQL*Plus.
- #
- # p.s. If you've used SQL*Plus's exec command all it does is wrap the
- # command in a BEGIN END; block for you.</PRE>
- <PRE>
- $csr = $db->prepare(q{
- BEGIN
- PLSQL_EXAMPLE.PROC_NP;
- END;
- });
- $csr->execute;</PRE>
- <PRE>
- # Example 2
- #
- # Now we call a procedure that has 1 IN parameter. Here we use bind_param
- # to bind out parameter to the prepared statement just like you might
- # do for an INSERT, UPDATE, DELETE, or SELECT statement.
- #
- # I could have used positional placeholders (e.g. :1, :2, etc.) or
- # ODBC style placeholders (e.g. ?), but I prefer Oracle's named
- # placeholders (but few DBI drivers support them so they're not portable).</PRE>
- <PRE>
- my $err_code = -20001;</PRE>
- <PRE>
- $csr = $db->prepare(q{
- BEGIN
- PLSQL_EXAMPLE.PROC_IN(:err_code);
- END;
- });</PRE>
- <PRE>
- $csr->bind_param(":err_code", $err_code);</PRE>
- <PRE>
- # PROC_IN will RAISE_APPLICATION_ERROR which will cause the execute to 'fail'.
- # Because we set RaiseError, the DBI will croak (die) so we catch that with eval.
- eval {
- $csr->execute;
- };
- print 'After proc_in: $@=',"'$@', errstr=$DBI::errstr, ret_val=$ret_val\n";</PRE>
- <PRE>
- # Example 3
- #
- # Building on the last example, I've added 1 IN OUT parameter. We still
- # use a placeholders in the call to prepare, the difference is that
- # we now call bind_param_inout to bind the value to the place holder.
- #
- # Note that the third parameter to bind_param_inout is the maximum size
- # of the variable. You normally make this slightly larger than necessary.
- # But note that the perl variable will have that much memory assigned to
- # it even if the actual value returned is shorter.</PRE>
- <PRE>
- my $test_num = 5;
- my $is_odd;</PRE>
- <PRE>
- $csr = $db->prepare(q{
- BEGIN
- PLSQL_EXAMPLE.PROC_IN_INOUT(:test_num, :is_odd);
- END;
- });</PRE>
- <PRE>
- # The value of $test_num is _copied_ here
- $csr->bind_param(":test_num", $test_num);</PRE>
- <PRE>
- $csr->bind_param_inout(":is_odd", \$is_odd, 1);</PRE>
- <PRE>
- # The execute will automagically update the value of $is_odd
- $csr->execute;</PRE>
- <PRE>
- print "$test_num is ", ($is_odd) ? "odd - ok" : "even - error!", "\n";</PRE>
- <PRE>
- # Example 4
- #
- # What about the return value of a PLSQL function? Well treat it the same
- # as you would a call to a function from SQL*Plus. We add a placeholder
- # for the return value and bind it with a call to bind_param_inout so
- # we can access it's value after execute.</PRE>
- <PRE>
- my $whoami = "";</PRE>
- <PRE>
- $csr = $db->prepare(q{
- BEGIN
- :whoami := PLSQL_EXAMPLE.FUNC_NP;
- END;
- });</PRE>
- <PRE>
- $csr->bind_param_inout(":whoami", \$whoami, 20);
- $csr->execute;
- print "Your database user name is $whoami\n";</PRE>
- <PRE>
- $db->disconnect;</PRE>
- <P>You can find more examples in the t/plsql.t file in the DBD::Oracle
- source directory.</P>
- <P>
- <HR>
- <H1><A NAME="private database handle functions">Private database handle functions</A></H1>
- <P>These functions are called through the method <CODE>func()</CODE>
- which is described in the DBI documentation.</P>
- <P>
- <H2><A NAME="plsql_errstr">plsql_errstr</A></H2>
- <P>This function returns a string which describes the errors
- from the most recent PL/SQL function, procedure, package,
- or package body compile in a format similar to the output
- of the SQL*Plus command 'show errors'.</P>
- <P>The function returns undef if the error string could not
- be retrieved due to a database error.
- Look in $dbh->errstr for the cause of the failure.</P>
- <P>If there are no compile errors, an empty string is returned.</P>
- <P>Example:</P>
- <PRE>
- # Show the errors if CREATE PROCEDURE fails
- $dbh->{RaiseError} = 0;
- if ( $dbh->do( q{
- CREATE OR REPLACE PROCEDURE perl_dbd_oracle_test as
- BEGIN
- PROCEDURE filltab( stuff OUT TAB ); asdf
- END; } ) ) {} # Statement succeeded
- }
- elsif ( 6550 != $dbh->err ) { die $dbh->errstr; } # Utter failure
- my $msg = $dbh->func( 'plsql_errstr' );
- die $dbh->errstr if ! defined $msg;
- die $msg if $msg;</PRE>
- <P>
- <H2><A NAME="dbms_output_enable / dbms_output_put / dbms_output_get">dbms_output_enable / dbms_output_put / dbms_output_get</A></H2>
- <P>These functions use the PL/SQL DBMS_OUTPUT package to store and
- retrieve text using the DBMS_OUTPUT buffer. Text stored in this buffer
- by dbms_output_put or any PL/SQL block can be retrieved by
- dbms_output_get or any PL/SQL block connected to the same database
- session.</P>
- <P>Stored text is not available until after dbms_output_put or the PL/SQL
- block that saved it completes its execution. This means you <STRONG>CAN NOT</STRONG>
- use these functions to monitor long running PL/SQL procedures.</P>
- <P>Example 1:</P>
- <PRE>
- # Enable DBMS_OUTPUT and set the buffer size
- $dbh->{RaiseError} = 1;
- $dbh->func( 1000000, 'dbms_output_enable' );</PRE>
- <PRE>
- # Put text in the buffer . . .
- $dbh->func( @text, 'dbms_output_put' );</PRE>
- <PRE>
- # . . . and retreive it later
- @text = $dbh->func( 'dbms_output_get' );</PRE>
- <P>Example 2:</P>
- <PRE>
- $dbh->{RaiseError} = 1;
- $sth = $dbh->prepare(q{
- DECLARE tmp VARCHAR2(50);
- BEGIN
- SELECT SYSDATE INTO tmp FROM DUAL;
- dbms_output.put_line('The date is '||tmp);
- END;
- });
- $sth->execute;</PRE>
- <PRE>
- # retreive the string
- $date_string = $dbh->func( 'dbms_output_get' );</PRE>
- <DL>
- <DT><STRONG><A NAME="item_dbms_output_enable">dbms_output_enable ( [ buffer_size ] )</A></STRONG><BR>
- <DD>
- This function calls DBMS_OUTPUT.ENABLE to enable calls to package
- DBMS_OUTPUT procedures GET, GET_LINE, PUT, and PUT_LINE. Calls to
- these procedures are ignored unless DBMS_OUTPUT.ENABLE is called
- first.
- <P>The buffer_size is the maximum amount of text that can be saved in the
- buffer and must be between 2000 and 1,000,000. If buffer_size is not
- given, the default is 20,000 bytes.</P>
- <P></P>
- <DT><STRONG><A NAME="item_dbms_output_put">dbms_output_put ( [ @lines ] )</A></STRONG><BR>
- <DD>
- This function calls DBMS_OUTPUT.PUT_LINE to add lines to the buffer.
- <P>If all lines were saved successfully the function returns 1. Depending
- on the context, an empty list or undef is returned for failure.</P>
- <P>If any line causes buffer_size to be exceeded, a buffer overflow error
- is raised and the function call fails. Some of the text might be in
- the buffer.</P>
- <P></P>
- <DT><STRONG><A NAME="item_dbms_output_get">dbms_output_get</A></STRONG><BR>
- <DD>
- This function calls DBMS_OUTPUT.GET_LINE to retrieve lines of text from
- the buffer.
- <P>In an array context, all complete lines are removed from the buffer and
- returned as a list. If there are no complete lines, an empty list is
- returned.</P>
- <P>In a scalar context, the first complete line is removed from the buffer
- and returned. If there are no complete lines, undef is returned.</P>
- <P>Any text in the buffer after a call to DBMS_OUTPUT.GET_LINE or
- DBMS_OUTPUT.GET is discarded by the next call to DBMS_OUTPUT.PUT_LINE,
- DBMS_OUTPUT.PUT, or DBMS_OUTPUT.NEW_LINE.</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="using dbd::oracle with oracle 8 features and issues">Using DBD::Oracle with Oracle 8 - Features and Issues</A></H1>
- <P>DBD::Oracle version 0.55 onwards can be built to use either the Oracle 7
- or Oracle 8 OCI (Oracle Call Interface) API functions. The new Oracle 8
- API is used by default and offers several advantages, including support
- for LOB types and cursor binding. Here's a quote from the Oracle OCI
- documentation:</P>
- <PRE>
- The Oracle8 OCI has several enhancements to improve application
- performance and scalability. Application performance has been improved
- by reducing the number of client to server round trips required and
- scalability improvements have been facilitated by reducing the amount
- of state information that needs to be retained on the server side.</PRE>
- <P>
- <H2><A NAME="prepare postponed till execute">Prepare postponed till execute</A></H2>
- <P>The DBD::Oracle module will avoid an explicit 'describe' operation
- prior to the execution of the statement unless the application requests
- information about the results (such as $sth->{NAME}). This reduces
- communication with the server and increases performance. However, it also
- means that SQL errors are not detected until <CODE>execute()</CODE> is called
- (instead of <CODE>prepare()</CODE> as now).</P>
- <P>
- <H2><A NAME="handling lobs">Handling LOBs</A></H2>
- <P>When fetching LOBs, they are treated just like LONGs and are subject to
- $sth->{LongReadLen} and $sth->{LongTruncOk}. Note that with OCI 7
- DBD::Oracle pre-allocates the whole buffer (LongReadLen) before
- constructing the returned column. With OCI 8 it grows the buffer to
- the amount needed for the largest LOB to be fetched so far.</P>
- <P>When inserting or updating LOBs some <EM>major</EM> magic has to be performed
- behind the scenes to make it transparent. Basically the driver has to
- refetch the newly inserted 'LOB Locators' before being able to write to
- them. However, it works, and I've made it as fast as possible, just
- one extra server-round-trip per insert or update after the first.
- For the time being, only single-row LOB updates are supported. Also
- passing LOBS to PL/SQL blocks doesn't work.</P>
- <P>To insert or update a large LOB, DBD::Oracle has to know in advance
- that it is a LOB type. So you need to say:</P>
- <PRE>
- $sth->bind_param($field_num, $lob_value, { ora_type => ORA_CLOB });</PRE>
- <P>The ORA_CLOB and ORA_BLOB constants can be imported using</P>
- <PRE>
- use DBD::Oracle qw(:ora_types);</PRE>
- <P>or just use the corresponding integer values (112 and 113).</P>
- <P>To make scripts work with both Oracle7 and Oracle8, the Oracle7
- DBD::Oracle will treat the LOB ora_types as LONGs without error.
- So in any code you may have now that looks like</P>
- <PRE>
- $sth->bind_param($idx, $value, { ora_type => 8 });</PRE>
- <P>you could change the 8 (LONG type) to ORA_CLOB or ORA_BLOB
- (112 or 113).</P>
- <P>One further wrinkle: for inserts and updates of LOBs, DBD::Oracle has
- to be able to tell which parameters relate to which table fields.
- In all cases where it can possibly work it out for itself, it does,
- however, if there are multiple LOB fields of the same type in the table
- then you need to tell it which field each LOB param relates to:</P>
- <PRE>
- $sth->bind_param($idx, $value, { ora_type=>ORA_CLOB, ora_field=>'foo' });</PRE>
- <P>
- <H2><A NAME="binding cursors">Binding Cursors</A></H2>
- <P>Cursors can now be returned from PL/SQL blocks. Either from stored
- procedure OUT parameters or from direct <CODE>OPEN</CODE> statements, as show below:</P>
- <PRE>
- use DBI;
- use DBD::Oracle qw(:ora_types);
- $dbh = DBI->connect(...);
- $sth1 = $dbh->prepare(q{
- BEGIN OPEN :cursor FOR
- SELECT table_name, tablespace_name
- FROM user_tables WHERE tablespace_name = :space
- END;
- });
- $sth1->bind_param(":space", "USERS");
- my $sth2;
- $sth1->bind_param_inout(":cursor", \$sth2, 0, { ora_type => ORA_RSET } );
- $sth1->execute();
- # $sth2 is now a valid DBI statement handle for the cursor
- while ( @row = $sth2->fetchrow_array ) { ... }</PRE>
- <P>The only special requirement is the use of <CODE>bind_param_inout()</CODE> with an
- attribute hash parameter that specifies <CODE>ora_type</CODE> as <CODE>ORA_RSET</CODE>.
- If you don't do that you'll get an error from the <CODE>execute()</CODE> like:
- ``ORA-06550: line X, column Y: PLS-00306: wrong number or types of
- arguments in call to ...''.</P>
- <P>
- <HR>
- <H1><A NAME="oracle related links">Oracle Related Links</A></H1>
- <P>
- <H2><A NAME="oracle on linux">Oracle on Linux</A></H2>
- <PRE>
- <A HREF="http://www.datamgmt.com/maillist.html">http://www.datamgmt.com/maillist.html</A>
- <A HREF="http://www.eGroups.com/list/oracle-on-linux">http://www.eGroups.com/list/oracle-on-linux</A>
- <A HREF="http://www.wmd.de/wmd/staff/pauck/misc/oracle_on_linux.html">http://www.wmd.de/wmd/staff/pauck/misc/oracle_on_linux.html</A>
- <A HREF="ftp://oracle-ftp.oracle.com/server/patch_sets/LINUX">ftp://oracle-ftp.oracle.com/server/patch_sets/LINUX</A></PRE>
- <P>
- <H2><A NAME="free oracle tools and links">Free Oracle Tools and Links</A></H2>
- <PRE>
- ora_explain supplied and installed with DBD::Oracle.</PRE>
- <PRE>
- <A HREF="http://vonnieda.org/oracletool/">http://vonnieda.org/oracletool/</A></PRE>
- <P>
- <H2><A NAME="commercial oracle tools and links">Commercial Oracle Tools and Links</A></H2>
- <P>Assorted tools and references for general information.
- No recommendation implied.</P>
- <PRE>
- <A HREF="http://www.platinum.com/products/oracle.htm">http://www.platinum.com/products/oracle.htm</A>
- <A HREF="http://www.SoftTreeTech.com">http://www.SoftTreeTech.com</A>
- <A HREF="http://www.databasegroup.com">http://www.databasegroup.com</A></PRE>
- <P>Also PL/Vision from RevealNet and Steven Feuerstein, and
- ``Q'' from Savant Corporation.</P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../site/lib/DBI.html">the DBI manpage</A></P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>DBD::Oracle by Tim Bunce. DBI by Tim Bunce.</P>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>The DBD::Oracle module is Copyright (c) 1995,1996,1997,1998,1999 Tim Bunce. England.
- The DBD::Oracle module is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself with the exception that it
- cannot be placed on a CD-ROM or similar media for commercial distribution
- without the prior approval of the author.</P>
- <P>
- <HR>
- <H1><A NAME="acknowledgements">ACKNOWLEDGEMENTS</A></H1>
- <P>A great many people have helped me over the years. Far too many to
- name, but I thank them all.</P>
- <P>See also <A HREF="../../../site/lib/DBI/acknowledgements.html">ACKNOWLEDGEMENTS in the DBI manpage</A>.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> DBD::Oracle - Oracle database driver for the DBI module</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-