zoukankan      html  css  js  c++  java
  • perl utf8 no utf8 utf8数据库

    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
    老干妈

  • 相关阅读:
    MySQL 5.7 Invalid default value for 'CREATE_TIME'报错的解决方法
    浅析mysql中exists 与 in 的使用
    mysql 索引原理
    内存溢出与内存泄漏
    java 内部类详解
    JAVA中重写equals()方法的同时要重写hashcode()方法
    Java中volatile关键字解析
    JDK1.8 HashMap源码分析
    mysql 行转列 列转行
    Java多线程(十)——线程优先级和守护线程
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349827.html
Copyright © 2011-2022 走看看