File: read_long_via_blob_read.pl

package info (click to toggle)
libdbd-oracle-perl 1.83-3
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 1,724 kB
  • sloc: ansic: 8,354; perl: 7,868; makefile: 20
file content (31 lines) | stat: -rw-r--r-- 725 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env perl

use strict;
use warnings;

use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:mydb', 'username', 'password' );

$dbh->{RaiseError} = 1;
$dbh->{LongTruncOk} = 1; # truncation on initial fetch is ok

my $sth = $dbh->prepare("SELECT key, long_field FROM table_name");
$sth->execute;

while ( my ($key) = $sth->fetchrow_array) {
    my $offset = 0;
    my $lump = 4096; # use benchmarks to get best value for you
    my @frags;
    while (1) {
        my $frag = $sth->blob_read(1, $offset, $lump);
        last unless defined $frag;
        my $len = length $frag;
        last unless $len;
        push @frags, $frag;
        $offset += $len;
    }
    my $blob = join "", @frags;
    print "$key: $blob\n";
}