DBD/DBI failing to add a blank in a non-null field

D

dn_perl

I am running into a problem with inserting a blank (not null) in a
non-null field via a placeholder.

sqlplus> desc mytable
fld01 not null varchar2(16) .


In Perl code :

use strict;
use DBI ;

my $dbh ; # DBI-> connect has been used to set value of $dbh
# database is Oracle 9i on solaris
my $user_id = ' ' ; # single space char in the string
my $dst = $dbh->prepare(" insert into
mytable (fld01) values(? ) " );
$dst->execute( $user_id ) or die "sql call failed." ;
---------------

But I get a DBD error that a null value cannot be entered into fld01. I
set $user_id to single-blank to insert a non-null value into
mytable.fld01 .

How can I add one space to mytable.fld01 ?

TIA.
 
M

Matt Garrish

I am running into a problem with inserting a blank (not null) in a
non-null field via a placeholder.

sqlplus> desc mytable
fld01 not null varchar2(16) .


In Perl code :

use strict;
use DBI ;

my $dbh ; # DBI-> connect has been used to set value of $dbh
# database is Oracle 9i on solaris
my $user_id = ' ' ; # single space char in the string
my $dst = $dbh->prepare(" insert into
mytable (fld01) values(? ) " );
$dst->execute( $user_id ) or die "sql call failed." ;

Oracle will strip the trailing spaces from the entry if it's a varchar
field, effectively leaving the entry null. See the documentation for the way
around this (ora_ph_type):

http://search.cpan.org/~timb/DBD-Oracle-1.16/Oracle.pm#Database_Handle_Attributes

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top