Skip to content

Problem selecting ROWID from Index Organized Table #31

@horrendo

Description

@horrendo

Unlike 'regular' tables, the value returned by the pseudo column ROWID for IOT's is not of fixed length.

I have an IOT with a multi-column primary key. When I try to select rows from the table and include ROWID, I get the following error:

DBD::Oracle::st fetchall_arrayref failed: ORA-01403: no data found (DBD ERROR: ORA-01406 error on field 4 of 4, ora_type 104) [for Statement "SELECT  t.*, t.rowid
FROM    t_iot t
"] at ./t-iot.plx line 60.

I'm not sure how to attach a test case so here's a simple self-contained perl script to reproduce the error:

#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
use DBD::Oracle;
use Time::HiRes qw(gettimeofday);
use POSIX qw(strftime);

use constant { MICRO_TO_HUNDREDTH => 10_000, };

sub log_it {
    my ( $sec, $usec ) = gettimeofday;
    print {*STDERR} sprintf( '%s.%02d ', strftime( '%d-%b-%Y %T', localtime($sec) ), ( $usec / MICRO_TO_HUNDREDTH ) ), @_, "\n";
    return;
}

sub create_table {
    my $dbh = shift;
    local $dbh->{'RaiseError'} = 0;
    local $dbh->{'PrintError'} = 0;
    log_it('Dropping table');
    $dbh->do(q(drop table t_iot));
    log_it('Creating table');
    $dbh->do(<<'END_SQL');
create table t_iot(
    c1      varchar2(30)
    ,c2     timestamp(6)
    ,c3     number
    ,constraint i_iot_pk primary key(c1, c2, c3)
    )
    organization index
        compress 2
END_SQL
    log_it('Populating table');
    $dbh->do(<<'END_SQL');
insert
into    t_iot
values  (rpad('a', 30, 'a'), current_timestamp, 1/81)
END_SQL
    log_it('Setup complete');
    return;
}

sub main {
    log_it('Using DBD::Oracle version ', $DBD::Oracle::VERSION);
    log_it('Connecting');
    my $dbh = DBI->connect( 'dbi:Oracle:', $ENV{'ORAPWD'}, '', );
    log_it('Connected !');

    create_table($dbh);
    log_it('Table created and populated');

    my $sql = <<'END_SQL';
select  t.*
from    t_iot t
END_SQL

    my $sth = $dbh->prepare($sql);
    log_it('Prepared (no rowid)');
    $sth->execute;
    log_it('Executed (no rowid)');
    my $data = $sth->fetchall_arrayref;
    log_it('Fetched ', (scalar @{$data}), ' rows (no rowid)');

    $sql = <<'END_SQL';
select  rowid
from    t_iot
END_SQL

    $sth = $dbh->prepare($sql);
    log_it('Prepared (rowid)');
    $sth->execute;
    log_it('Executed (rowid)');
    $data = $sth->fetchall_arrayref;
    log_it('Fetched ', (scalar @{$data}), ' rows (rowid)');

    $dbh->disconnect;
    log_it('Disconnected');
    return 0;
} ## end sub main

exit main();

My output (connecting to an Oracle 11.2.0.4 DB using the 12.1 instant client on RHEL6) is:

[stbaldwin@audev04 dev][1]☢ ORAPWD=xxx/yyy@aulevdev ./t-iot.plx
10-Jul-2015 11:52:54.90 Using DBD::Oracle version 1.74
10-Jul-2015 11:52:54.90 Connecting
10-Jul-2015 11:52:54.98 Connected !
10-Jul-2015 11:52:54.98 Dropping table
10-Jul-2015 11:52:55.12 Creating table
10-Jul-2015 11:52:55.19 Populating table
10-Jul-2015 11:52:55.20 Setup complete
10-Jul-2015 11:52:55.20 Table created and populated
10-Jul-2015 11:52:55.21 Prepared (no rowid)
10-Jul-2015 11:52:55.21 Executed (no rowid)
10-Jul-2015 11:52:55.21 Fetched 1 rows (no rowid)
10-Jul-2015 11:52:55.21 Prepared (rowid)
10-Jul-2015 11:52:55.21 Executed (rowid)
DBD::Oracle::st fetchall_arrayref failed: ORA-01403: no data found (DBD ERROR: ORA-01406 error on field 1 of 1, ora_type 104) [for Statement "select  rowid
from    t_iot
"] at ./t-iot.plx line 74.
10-Jul-2015 11:52:55.22 Fetched 0 rows (rowid)
DBI::db=HASH(0x1ce0908)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) at ./t-iot.plx line 77.
10-Jul-2015 11:52:55.22 Disconnected

Thanks and regards,

Steve

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions