Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:07:57+00:00 2026-05-27T13:07:57+00:00

I’d like to know the most memory-efficient way to pull arbitrarily large data fields

  • 0

I’d like to know the most memory-efficient way to pull arbitrarily large data fields from an Oracle db with Perl DBI. The method I know to use is to set the ‘LongReadLen’ attribute on the database handle to something sufficiently large. However, my application needs to pull several thousand records, so doing this arbitarily is extremely memory inefficient.

The doc suggests doing a query upfront to find the largest potential value, and setting that.

$dbh->{LongReadLen} = $dbh->selectrow_array(qq{
    SELECT MAX(OCTET_LENGTH(long_column_name))
    FROM table WHERE ...
});
$sth = $dbh->prepare(qq{
    SELECT long_column_name, ... FROM table WHERE ...
});

However, this is still inefficient, since the outlying data is not representative of every record. The largest values are in excess of a MB, but the average record is less than a KB. I want to be able to pull all of the informatoin (i.e., no truncation) while wasting as little memory on unused buffers as possible.

A method I’ve considered is to pull the data in chunks, say 50 records a time, and set LongReadLen against the max length of records of that chunk. Another work around, which could, but doesn’t have to, build on the chunk idea, would be to fork a child process, retrieve the data, and then kill the child (taking the wasted memory with it). The most wonderful thing would be the ability to force-free the DBI buffers, but I don’t think that’s possible.

Has anyone addressed a similar problem with any success? Thanks for the help!

EDIT

Perl v5.8.8, DBI v1.52

To clarify: the memory inefficiency is coming from using ‘LongReadLen’ together with {ora_pers_lob => 1} in the prepare. Using this code:

my $sql = "select myclob from my table where id = 68683";
my $dbh = DBI->connect( "dbi:Oracle:$db", $user, $pass ) or croak $DBI::errstr;

print "before";
readline( *STDIN );

$dbh->{'LongReadLen'} = 2 * 1024 * 1024;
my $sth = $dbh->prepare( $sql, {'ora_pers_lob' => 1} ) or croak $dbh->errstr;
$sth->execute() or croak( 'Cant execute_query '. $dbh->errstr . ' sql: ' . $sql );
my $row = $sth->fetchrow_hashref;

print "after";
readline( *STDIN );

Resident memory usage “before” is at 18MB and usage “after” is at 30MB. This is unacceptable over a large number of queries.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:07:57+00:00Added an answer on May 27, 2026 at 1:07 pm

    Are your columns with large data LOBs (CLOBs or BLOBs)? If so, you don’t need to use LongReadLen at all; DBD::Oracle provides a LOB streaming interface.

    What you want to do is to bind the param as type ORA_CLOB or ORA_BLOB, which will get you a “LOB locator” returned from the query, instead of tex. Then you use ora_lob_read together with the LOB locator to get data. Here’s an example of code that’s worked for me:

    sub read_lob {
      my ( $dbh, $clob ) = @_;
    
      my $BLOCK_SIZE = 16384;
    
      my $out;
      my $offset = 1;
    
      while ( my $data = $dbh->ora_lob_read( $clob, $offset, $BLOCK_SIZE ) ) {
        $out .= $data;
        $offset += $BLOCK_SIZE;
      }
      return $out;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.