Oracle-Specific MethodsThere are a number of special Perl DBI methods that support the use of DBD::Oracle and its handling of particular Oracle datatypes and operations. DBMS_OUTPUT MethodsFour additional functions, available within DBD::Oracle, are provided for use in accessing Oracle's DBMS_OUTPUT built-in package; they are listed in Table B-6.
The following code illustrates the use of some of these private methods: #! perl -w use strict; use DBI; # Step 1: Connect to orcacle database, orcl. my $dbh = DBI->connect('dbi:Oracle:orcl', 'scott', 'tiger'), {RaiseError => 1, AutoCommit => 0} ); # Step 2: Enable the later collection of DBMS_OUTPUT information. $dbh->func( 1_000_000, 'dbms_output_enable'); # Step 3: Prepare and run some anonymous PL/SQL containing some # output from DBMS_OUTPUT. my $sth = $dbh->prepare(q{ DECLARE hello_string VARCHAR2(50); BEGIN SELECT 'Hello ' || USER || '! :-)' INTO hello_string FROM DUAL; dbms_output.put_line( hello_string ); END; }); $sth->execute; # Step 4: Get the output and print it out. print $dbh->func( 'dbms_output_get' ), "\n"; $dbh->disconnect; Let's see what's going on here.
Handling LOBsWhen DBD::Oracle fetches LOBs (large objects), they are treated as LONGs and are subject to the LongReadLen and LongTruncOk handle attributes described earlier. Note that at the time of this writing, only single-row LOB updates were supported, and the ability to pass LOBS to PL/SQL blocks was not available. Consider the following examples:
Binding CursorsDBD::Oracle returns cursors from PL/SQL blocks as shown here: use DBI; use DBD::Oracle qw(:ora_types); my $dbh = DBI->connect('dbi:Oracle:orcl', 'scott', 'tiger'), {RaiseError => 1, AutoCommit => 0} ); my $sth = $dbh->prepare(q{ BEGIN OPEN :cursor FOR SELECT deptno, dname, loc FROM dept FROM user_tables WHERE loc = :loc; END; }); $sth->bind_param(":loc", "BOSTON"); my $sth_curs; $sth->bind_param_inout(":cursor", \$sth_curs, 0, { ora_type => ORA_RSET } ); $sth->execute; # $sth_curs can now be used like any other statement handle... while ( @row = $sth_curs->fetchrow_array ) { ... Notice how ora_type is set to ORA_SET; this is mandatory. See the curref.pl script in the Oracle.ex directory in DBD::Oracle's source distribution for more examples. |