I use DBI 1.14 and DBD::Oracle 1.06. I have noticed that
by default, DBI will not padd the text literals in the where
condition with blanks. This causes matching records fail
against oracle database.

For example, here sqlplus automatically pads the text literal
so that matches are found:

SQL> desc usr
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 CHAR(16)
 NAME                                               CHAR(32)
 GRP                                                CHAR(16)

SQL> select '|' || GRP || '|'  from usr where GRP='foo'

'|'||GRP||'|'
------------------
|foo             |
|foo             |

But if you use DBI like this:
        $sth=$dbh->prepare('SELECT * FROM usr WHERE grp = ?) or die $!;
        $sth->bind_param(1,'foo');
        $sth->execute;
then no matches are found. The work around I find is to do this:

        use DBD::Oracle qw(:ora_types);
        $sth->bind_param(1,'foo',{ ora_type => ORA_CHAR });

But I don't really like this work around that much because it
made my code not portable for such basic data types.

Is this a DBI bug/feature? Are there better ways to deal with it?

Thanks for any info.

Richard

Reply via email to