A colleague asked for help with the below script.
As I have not worked with 10g and could not find a
relevant FAQ I thought perhaps you gentle folks would
nudge me in the right direction :-)
Jacqui
[EMAIL PROTECTED]:~/tmp$ cat dbi-test.pl
use strict;
use DBI;
#use utf8;
#use bytes;
#use encoding 'latin1';
#use encoding 'utf8';
#$ENV{NLS_LANGUAGE} = 'WE8ISO8859P1';
my $dbname = 'aaa';
my $dbuser = 'bbb';
my $dbpass = 'ccc';
my $dbh = DBI->connect_cached($dbname,$dbuser,$dbpass)
or die "Connection error. ($dbname,$dbuser,$pdbpass)$DBI::errstr'\n";
$dbh->do('CREATE TABLE SC_TEST ( B BLOB, C CLOB, V VARCHAR2(160))');
foreach my $v (qw(a b 0 1 £ á é $ £)) {
test_vals($v,$v,$v);
}
$dbh->do('DROP TABLE SC_TEST CASCADE CONSTRAINTS');
$dbh->disconnect();
exit;
sub test_vals { my ($b,$c,$v) = @_;
display_values('storing',$b,$c,$v);
{my $sth = $dbh->prepare_cached('insert into SC_TEST (B, C, V)
values (RAWTOHEX(?), ?, ?)');
$sth->execute($b, $c, $v);
$sth->finish();
}
{my $sth = $dbh->prepare_cached('select B, C, V from SC_TEST');
$sth->execute();
while (my ($bv, $cv, $vv) = $sth->fetchrow_array()) {
display_values('fetched',$bv,$cv,$vv);
}
$sth->finish();
}
$dbh->do('delete from SC_TEST');
}
sub display_values { my ($where,$b,$c,$v) = @_;
print STDERR "$where\n";
print STDERR "B=($b) (".iso2hex($b).")\n";
print STDERR "C=($c) (".iso2hex($c).")\n";
print STDERR "V=($v) (".iso2hex($v).")\n";
return;
}
sub iso2hex($) {
my $rv = join(' ',map {sprintf('%lx',$_)} unpack('U*',$_[0]));
return $rv;
}
[EMAIL PROTECTED]:~/tmp$ perl dbi-test.pl
storing
B=(a) (61)
C=(a) (61)
V=(a) (61)
fetched
B=(a) (61)
C=(a) (61)
V=(a) (61)
storing
B=(b) (62)
C=(b) (62)
V=(b) (62)
fetched
B=(b) (62)
C=(b) (62)
V=(b) (62)
storing
B=(0) (30)
C=(0) (30)
V=(0) (30)
fetched
B=(0) (30)
C=(0) (30)
V=(0) (30)
storing
B=(1) (31)
C=(1) (31)
V=(1) (31)
fetched
B=(1) (31)
C=(1) (31)
V=(1) (31)
storing
B=(£) (a3)
C=(£) (a3)
V=(£) (a3)
fetched
B=(¿) (bf)
C=(?) (3f)
V=(?) (3f)
storing
B=(á) (e1)
C=(á) (e1)
V=(á) (e1)
fetched
B=(¿) (bf)
C=(?) (3f)
V=(?) (3f)
storing
B=(é) (e9)
C=(é) (e9)
V=(é) (e9)
fetched
B=(¿) (bf)
C=(?) (3f)
V=(?) (3f)
storing
B=($) (24)
C=($) (24)
V=($) (24)
fetched
B=($) (24)
C=($) (24)
V=($) (24)
storing
B=(£) (a3)
C=(£) (a3)
V=(£) (a3)
fetched
B=(¿) (bf)
C=(?) (3f)
V=(?) (3f)
[EMAIL PROTECTED]:~/tmp$
[EMAIL PROTECTED]:~/tmp$ uname -a
Linux dev 2.4.27ru #1 SMP Mon May 2 15:24:13 CEST 2005 i686 GNU/Linux
[EMAIL PROTECTED]:~/tmp$ sqlplus ...
SQL*Plus: Release 10.1.0.3.0 - Production on Mon Jul 11 15:03:24 2005
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Release 10.1.0.3.0 - Production
SQL> Disconnected from Oracle Database 10g Release 10.1.0.3.0 - Production
[EMAIL PROTECTED]:~/tmp$ perl -v
This is perl, v5.8.6 built for i686-linux
Copyright 1987-2004, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
[EMAIL PROTECTED]:~/tmp$ perl -MDBI=99999
DBI version 99999 required--this is only version 1.46 at
/usr/local/lib/perl5/5.8.6/Exporter/Heavy.pm line 121.
BEGIN failed--compilation aborted.
perl -MDBD::Oracle=99999
DBD::Oracle version 99999 required--this is only version 1.16 at
/usr/local/lib/perl5/5.8.6/Exporter/Heavy.pm line 121.
BEGIN failed--compilation aborted.
[EMAIL PROTECTED]:~/tmp$