Automatically setting your NLS_LANG shell variable

This short script is usefull to automatically set your NLS_LANG shell variable to the correct value, whch mathces to your database. This script connects to the database, retrieves the NLS_LANG value and sets it in your shell. Its called by my rman backup scripts and by my export scripts, both of which, need this variable set. If you are supporting multiple databases which differenct charactersets, this script is a must, unless you want to manually connect to the database, run the queries against v$nls_parameters and set it manually.



sqlplus -s "/ as sysdba" <<'EOF'>${TMPFILE}
set serveroutput on
set echo off head off feed off
  v_language varchar2(100);
  v_territory varchar2(100);
  v_characterset varchar2(100);
  select value into v_language from v$nls_parameters where parameter='NLS_LANGUAGE';
  select value into v_territory from v$nls_parameters where parameter='NLS_TERRITORY';
  select value into v_characterset from v$nls_parameters where parameter='NLS_CHARACTERSET';
  dbms_output.put_line('export NLS_LANG='||v_language||'_'||v_territory||'.'||v_characterset);
eval $(< ${TMPFILE} )
rm -f ${TMPFILE}
if [ -z ${NLS_LANG} ]
echo "JOB_${ORACLE_SID} $prog ERROR. NLS_LANG not set."
echo "Setting NLS_LANG to: "$NLS_LANG

Copyright © 2007, All rights reserved by RudnikConsulting Inc