perl utf8 插入数据库:
[oracle@oadb sbin]$ cat insertdb.pl
use DBI;
use Encode;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
my $a="老干妈";
# $a=encode_utf8($a);
print length($a);
print "
";
print $a;
my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
$dbh->do("insert into tlcb values('$a')");
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$
[oracle@oadb sbin]$ perl insertdb.pl
9
老干妈[oracle@oadb sbin]$
SQL> select dump(name),name from tlcb;
DUMP(NAME)
--------------------------------------------------------------------------------
NAME
--------------------
Typ=96 Len=20: 232,128,129,229,185,178,229,166,136,32,32,32,32,32,32,32,32,32,32
,32
老干妈
启用utf8:
[oracle@oadb sbin]$ cat insertdb.pl
use DBI;
use Encode;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
use utf8;
my $a="老干妈";
# $a=encode_utf8($a);
print length($a);
print "
";
print $a;
my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
$dbh->do("insert into tlcb values('$a')");
[oracle@oadb sbin]$ perl insertdb.pl
3
Wide character in print at insertdb.pl line 10.
老干妈[oracle@oadb sbin]$
Typ=96 Len=20: 232,128,129,229,185,178,229,166,136,32,32,32,32,32,32,32,32,32,32
,32
老干妈
Typ=96 Len=20: 232,128,129,229,185,178,229,166,136,32,32,32,32,32,32,32,32,32,32
,32
老干妈