6

I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3).

I've set the NLS_LANG variable in .bash_profile.

[app@box stasis]$ echo $NLS_LANG
en_US.UTF-8
[app@box stasis]$ which ruby
~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby

However when trying to access it via ruby (which the oci8 driver does), it cannot find it:

 1.9.3-p194 :001 > ENV['NLS_LANG']
 => nil 

Accessing other vars seems to work:

 1.9.3-p194 :004 > ENV['USER']
 => "app"

My script shows the following: Warning: NLS_LANG is not set. fallback to US7ASCII.

Thing is I'm running sqlplus from the ruby script (to execute some .sql files), and special characters are all messed up.

How can I get ruby to see the value?

robertrv
  • 695
  • 2
  • 11
  • 16

1 Answers1

12

You need to export your variables to be available in any applications run (unless they are functions):

export NLS_LANG

or together with setting:

export NLS_LANG=en_US.UTF-8

or as on most systems LANG should be available:

export NLS_LANG=$LANG
mpapis
  • 52,729
  • 14
  • 121
  • 158
  • 1
    Does LANG really contain the format that Oracle expects in NLS_LANG? –  May 11 '12 at 22:03
  • 12
    Thanks! Turns out I wasn't exporting the variable. 'en_US.UTF-8' did not work though (oci8 said it was invalid). I used `NLS_LANG=AMERICAN_AMERICA.UTF8` and oci8 did not complaint about it. – robertrv May 11 '12 at 22:05
  • 3
    So this is ancient, but please remember that UTF8 is not UTF8 in Oracle. You need to use AL32UTF8. http://wonderingmisha.blogspot.jp/2011/10/utf8-vs-al32utf8.html – polm23 Apr 26 '13 at 09:27