Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have a problem in inserting Spanish characters(accent) into Oracle. I run the perl script after setting "export NLS_LANG=American_America.UTF8". but still the accents č not been inserted properly. Could anyone help me to fix this issue? Thanks for your help. Regards, Raja
  • Comment on Problem in inserting Spanish characters(accent) into Oracle

Replies are listed 'Best First'.
Re: Problem in inserting Spanish characters(accent) into Oracle
by graff (Chancellor) on Feb 01, 2006 at 05:23 UTC
    Maybe if you show us a relevant snippet of the code you've written for this? Also, what exactly is showing up in the database instead of the accented characters you want?

    (Hmm... è in Spanish??? Don't you mean é?)

    update: One other point: have you tried printing the data to stdout or a plain-text file? This might help to make sure that you really have the accented characters as utf8 in your script. (In other words, you need to make sure that the characters are encoded correctly as utf8.)

      Here is the code snapshot, my $insert_sql = qq! insert into C_LANG_ITEMS (lang_code,key,final_translation) values('ES',:1,:2) !; Here is the data, - Seleccione al menos un término de carga

        You haven't told us yet how the oracle content is different from what you expected to get. What are you using to look at the table contents after the insert is done, and what do you see when you look at that?

        It could be that you really are getting the utf8 character data into oracle correctly, but maybe you aren't seeing it as utf8 data when you pull it back out. The DBD::Oracle driver might not be setting the utf8 flag on scalar string values that come back from the database.

        If that's the case, you may need to do something like:

        use Encode; # ... do whatever it takes to query for inserted text, # and assign the "Spanish" string from the DB to $fldvalue ... # the string value from the DB is not flagged as utf8 in Perl, # so set the utf8 flag: my $fldvalue = decode( 'utf8', $fldvalue );
Re: Problem in inserting Spanish characters(accent) into Oracle
by olus (Curate) on Feb 01, 2006 at 14:19 UTC
    You don't have to care setting NLS_LANG with export every time you want to run the script. You may forget it sometime.
    You can set that at the top of your script like this:
    $ENV{NLS_LANG} = "AMERICAN_AMERICA.UTF8";
    As to the characters being correctly inserted, try and run a test using module Unicode::MapUTF8

    Insert a string converting it into UFT8 from the charset you are using, and then, upon retrieving the string, you convert it from UTF8 into the charset you are working with.

    In the example bellow I use the charset suitable for portuguese. It is latin 1, so it should suit your needs
    use Unicode::MapUTF8 qw(to_utf8 from_utf8); ... #convert into utf8 $str = to_utf8({ -string => 'Your string here', -charset => 'ISO-8859- +1' }); # TODO: insert into DB ..... # TODO: select stuff from database, and then $str = from_utf8({-string => $str_retrieved, -charset => 'ISO-8859-1' +}); # TODO: now check the value of $str