Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > retrieving CLOB from an Oracle stored function within perl

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-02-07, 19:38
andrewkl andrewkl is offline
Registered User
 
Join Date: Nov 2007
Posts: 5
retrieving CLOB from an Oracle stored function within perl

Hi,

I'm trying to retrieve data (CLOB, string, integer) from a stored function.
My example code looks like:

###########

$dbh = DBI->connect(....) or die "can't connect";

$stmt = 'BEGIN :cursor := foo; END;';
$sth = $dbh->prepare ($stmt);
$sth->bind_param_inout(":cursor", \$refCursor, 0, { ora_type => ORA_RSET } );

$sth->execute();
while ( my ($clob, $str, $num)= $refCursor->fetchrow_array ) {
print "$clob, $str, $num\n";
}
$sth->finish();

--------

When I run my perl script, I get:

OCILobLocatorPtr=SCALAR(0x4cbdec), hello there, 1
OCILobLocatorPtr=SCALAR(0x4cbe4c), bye now, 2


How can I get the value of the CLOB data?


################################################## ##############

The stored function foo() looks like:

FUNCTION foo
RETURN ref_cursor_type
IS
/* ---- TYPE ref_cursor_type is REF CURSOR; */
ref_cursor ref_cursor_type;
BEGIN
OPEN ref_cursor
FOR SELECT clob_col, string_col, int_col FROM foo_table ;
RETURN ref_cursor;
END;

################################################## ##############

The foo_table looks like:

CREATE TABLE foo_table
(
clob_col CLOB,
string_col VARCHAR2 (100),
int_col NUMBER
);

Contents of foo_table are:

CLOB_COL STRING_COL INT_COL
-----------------------------------------
testing hello there 1
another test bye now 2

################################################## ##############


Thanks
--Andrew
Reply With Quote
  #2 (permalink)  
Old 11-03-07, 04:56
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Fort Polk, LA
Posts: 500
Normally DBI handles CLOBs as big scalars. It has some attributes that let you truncate them so that really big ones don't take up all your memory, but aside from that, it doesn't return references.

Here's the relevant manual page on DBD::Oracle. It looks confusing to me, but if you go down a bit there are some helpful looking examples.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On