If you run the code below (bare in mind it drops a table called testutf) does it work? Are the files uni.out and utf.out the same afterwards?

You can always change it to put more Asian characters in the initial string.

#!/usr/bin/perl -w use strict; use warnings; use DBI qw(:utils); use charnames ':full'; use Encode; binmode(STDOUT, ":utf8"); my $str = "\x{263a}xxx" . chr(0x05d0) . "\N{ARABIC LETTER ALEF}"; print $str, "\n"; print join(" ", unpack("H*", $str)), "\n"; print "length(str) = ", length($str), "\n"; print "bytes::length(str) = ", bytes::length($str), "\n"; print "utf8::is_utf8 = ", utf8::is_utf8($str) ? 1 : 0, "\n"; print "data_string_desc: ", data_string_desc($str),"\n"; open OUT, ">uni.out"; binmode(OUT, ":utf8"); print OUT "$str\n"; my $dbh = DBI->connect("dbi:Oracle:XX", "XX", "XX",{oracharset => 'AL3 +2UTF8', ChopBlanks => 1}); $dbh->do("drop table testutf"); $dbh->do("create table testutf (a char(100))"); my $sth = $dbh->prepare("insert into testutf values (?)"); $sth->execute($str); $sth = $dbh->prepare("select * from testutf"); $sth->execute; my @row = $sth->fetchrow_array; print "data_string_desc (after fetch): ", data_string_desc($row[0]),"\ +n"; print join(" ", unpack("H*", $row[0])), "\n"; open OUT, ">utf.out"; binmode (OUT, ":utf8"); print OUT $row[0]; close OUT;

We use unicode in Oracle all the time with japanese, chinese, arabic and many other languages and it works fine so long as the database and character set are set to AL32UTF8. Also bare in mind there are oracle database downloads (I think for Oracle XE) which are not labeled "international" and don't do unicode.

Lastly, what you see when you print unicode to your terminal is no indication of whether the data you retrieved is correct or not - that largely depends on how your terminal is set up and whether your system can display the characters you have output.


In reply to Re^3: set unicode in perl by mje
in thread set unicode in perl by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.