Detecting clientside NLS_LANG setting in SQL*Plus script

Our company has developed an application that uses an Oracle database as it backend. Companies can buy our application and run it against their own Oracle installation.
A new version of our application often requires an update to the Oracle database schema.
Together with new application files we send our customers an update.sql script they must run against their database using SQL*Plus.
This update script may contain international characters like é for example:
UPDATE SHOPS SET DESCRIPTION = 'Café'
WHERE SHOP_ID=1We save the SQL-script file in windows-1252 encoding so the character é is encoded as 0xE9 in the script file.
When the DBA running the upgrade script has set NLS_LANG=.WE8MSWIN1252 this works perfectly.
When the DBA has set his NLS_LANG=US7ASCII the é gets replaced by an upside-down question mark. Other NLS_LANG settings can also be troublesome.
To prevent this we give very clear installation instructions. However, nobody reads them. This leads to two questions:
A) Is there a way to prevent this problem so I do not depend on the NLS_LANG setting by the DBA running the upgrade script?
B) Otherwise: is there a way to test for the NLS_LANG setting inside the script and abort if it is not WE8MSWIN1252?
Info:
Database is 10.2.0.3/10.2.0.4 and sometimes 10.2.0.5, always database character set WE8MSWIN1252.
Client software: I do not know what each DBA uses but it will be mostly 10g client software
Client OS: Some DBA's will be running the script from Windows, others from some Unix variety. I cannot control that.

I agree with Sergiusz. You're much better off if you can remove character set dependencies from your scripts by using commands like this.
UPDATE SHOPS SET DESCRIPTION =  unistr( 'Caf\00E9' )
WHERE SHOP_ID=1 ;If that's not possible however you can try this approach to determine the session's character set.
SQL> column USERENV_LANGUAGE format a30
SQL> column oracle_charset   format a20
SQL> r
  1  select
  2    userenv_language
  3  , substr
  4    ( userenv_language
  5    , instr( userenv_language, '.' ) + 1
  6    ) as oracle_charset
  7  from
  8  ( select sys_context( 'USERENV', 'LANGUAGE' ) as userenv_language
  9    from dual
10* )
USERENV_LANGUAGE               ORACLE_CHARSET
AMERICAN_AMERICA.AL32UTF8      AL32UTF8 --
Joe

Similar Messages

  • How to detect client OS from SQL*Plus script

    Sometimes in a SQL*Plus script I need to execute OS commands e.g.
    host rm tempfile.bufHowever of course Windows has no "rm" command by default, so I have to edit the script to use
    host del tempfile.bufNow if I could define &DELETE (for example, "cat"/"type" is another) as a substitution variable, I could just use
    host &DELETE tempfile.bufMaybe I need more coffee but all I could come up with was something like this:
    def rm=rm
    def cat=cat
    spool sqlplus_windows_defs.cmd
    prompt echo def rm=del
    prompt echo def cat=type
    spool off
    host .\sqlplus_windows_defs > sqlplus_windows_defs.sql
    @sqlplus_windows_defs.sql
    host &rm sqlplus_windows_defs.cmd
    host &rm sqlplus_windows_defs.sqlthe idea being that you first define the variables for nix ("rm" and "cat"), then attempt to create and execute a Windows command file containing DOS versions ("dele" and "type"), which does not run under nix. Unfortunately the OS failure message (".sqlplus_windows_defs: not found" in Unix) appears on the screen despite SET TERM OFF, so I'm back where I started.
    I know there are various ways to get the server OS, and you can get the SQL*Plus version with &_SQLPLUS_RELEASE and so on, but I can't see a way to determine the client OS. Any suggestions?

    Thanks guys. This seems to work in Windows XP - will try on Unix when I get a chance:
    col DELETE_COMMAND new_value DELETE_COMMAND
    col LIST_COMMAND new_value LIST_COMMAND
    def list_command = TYPE
    def delete_command = DEL
    SELECT DECODE(os,'MSWIN','TYPE','cat') AS list_command
         , DECODE(os,'MSWIN','DEL','rm')   AS delete_command
    FROM   ( SELECT CASE WHEN UPPER(program) LIKE '%.EXE' THEN 'MSWIN' END AS os
             FROM   v$session
             WHERE  audsid = SYS_CONTEXT('userenv','sessionid') );
    host &LIST_COMMAND xplan_errors.lst
    host &DELETE_COMMAND xplan_errors.lstIf the user doesn't have access to v$session it will just default to the Windows commands.
    http://www.williamrobertson.net/code/xplan.sql

  • Execute SQL*PLUS script from VB6?

    I'm using VB6 to connect to oracle 10 with oracle client 8i, I can establish the connection without any problems.
    If I run a SQL statement from VB it works prefect, but when I try to run a SQL Plus script from VB I get error ORA-00900, "invalid SQL statement". Everything works fine in oracle SQLPLUS.
    Is there anything I have missed about running SQL*PLUS script from VB6? Is'nt it the same as a SQL statement?

    Thanks for you answer Justin,
    This is a short variant of SQL*Plus I wanna execute from VB and transfer the result into a listview in VB.
    If this is possible from VB, can you show me how I should do?
    COLUMN customer_1 NEW_VALUE customer_1 NOPRINT
    COLUMN customer_2 NEW_VALUE customer_2 NOPRINT
    SELECT customer customer_1
      FROM (
            SELECT customer,
                   ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
              FROM (
                    SELECT  customer,
                            SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                      FROM  CustTable
                      WHERE year_month BETWEEN 200709 AND 200801
    WHERE CustomerTotalSalesRank = 1
      AND ROWNUM = 1
    SELECT customer customer_2
      FROM (
            SELECT customer,
                   ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
              FROM (
                    SELECT  customer,
                            SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                      FROM  CustTable
                      WHERE year_month BETWEEN 200709 AND 200801
    WHERE CustomerTotalSalesRank = 2
      AND ROWNUM = 1
    SET VERIFY OFF
    SELECT  year_month,
            SUM(
                CASE CustomerTotalSalesRank
                  WHEN 1
                    THEN
                      SalesQty
                    ELSE
                      NULL;
                END
               ) "&customer_1",
            SUM(
                CASE CustomerTotalSalesRank
                  WHEN 2
                    THEN
                      SalesQty
                    ELSE
                      NULL;
                END
               ) "&customer_2"
    FROM  (
             SELECT  year_month,
                     SalesQty,
                     ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
               FROM  (
                      SELECT  customer,
                              year_month,
                              SalesQty,
                              SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                        FROM  CustTable
                        WHERE year_month BETWEEN 200709 AND 200801
      WHERE CustomerTotalSalesRank <= 10
      GROUP BY year_month
      ORDER BY year_month
      /

  • SQL*Plus script with a dynamic SPOOL File Location?

    Anyone,
    I have a numbr of SQL Plus scripts that I need to run many times but each run against a different database. Each script SPOOLS the output like this:
    spool c:\temp\BUILD_ASSET.lis
    spool c:\temp\BUILD_WORKORDER.lis
    etc
    (each spool is a seperate script run)
    The spool is at the top of each BUILD SQL Script.
    Example:
    set time on
    SET FEEDBACK ON
    SET ECHO ON
    SET TIMING ON
    spool c:\temp\BUILD_ASSET.lisBut I need each run to go into its own directory based on the database I am connected to. Like this:
    CONNECT DB1
    @C:\temp\BUILD_ASSET.SQL =====> spool c:\temp\DB1\BUILD_ASSET.lis
    @c:\temp\BUILD_WORKORDER.SQL =====>  spool c:\temp\DB1\BUILD_WORKORDER.lis
    etc
    CONNECT DB2
    @C:\temp\BUILD_ASSET.SQL =====> spool c:\temp\DB2\BUILD_ASSET.lis
    @c:\temp\BUILD_WORKORDER.SQL =====> spool c:\temp\DB2\BUILD_WORKORDER.lisIs there a way to dynaically code this without having to create a version of the BUILD scripts for every single DB I connect to?
    I would like to have one big script that executes all the individual BUILD scripts.
    Seems very easy in concept but I can not see an easy way. I would appreciate any help I can get.
    Thanks in advance,
    Miller

    column db new_Value db
    select sys_context('userenv','db_name') db from dual;
    spool c:\temp\&db\file.lis

  • Is there some time setting in sql*plus or Oracle9i

    Hi guys,
    I just run the following simple query in sql*plus in oracle 9i:
    select * from pers ;
    The table is around 190k rows. But it always stops running after 28-30minutes. No error message displayed and the whole sql*plus just hang on there.... The only thing I can do is to restart the sql*plus.
    I got this problem when I run some other query, so I use this simple query just to test if it will stop after running 30m. Now it does. I'm thinking there is some setting in sql*plus or ORACL9i I need to do. Could someone help me to solve this problem?
    Thanks in advance,

    Hi,
    you can check out this information in the user_resource_limits table.
    select * from user_resource_limits;
    COMPOSITE_LIMIT UNLIMITED
    SESSIONS_PER_USER UNLIMITED
    CPU_PER_SESSION UNLIMITED
    CPU_PER_CALL UNLIMITED
    LOGICAL_READS_PER_SESSION UNLIMITED
    LOGICAL_READS_PER_CALL UNLIMITED
    IDLE_TIME UNLIMITED
    CONNECT_TIME UNLIMITED
    PRIVATE_SGA UNLIMITED
    Thanks.

  • Set Up SQL*Plus Issue

    Folks,
    Hello. My Operating System is Oracle Linux 5. Database is Oracle DB 11gR1.
    I have tried to set up SQL*Plus in the following way:
    My directory: /home/myOracle/OracleDB_Home/bin
    SYSTEM_PASS=SYSTEM/SYSTEM
    export SYSTEM_PASS
    ./sqlplus SYSTEM/SYSTEM
    But this message comes up:
    Error 6 initializing SQL*Plus
    Message file sql<lang>.msb not found
    SP2-0750: You may need to set ORACLE_HOME to your Oracle Software directory.
    Where is message file sql<lang>.msb ? What is Oracle Software directory ?
    Can any folk help to solve this issue ?

    Duplicate post
    Re: Set Up SQL*Plus Issue

  • SQL Plus Script Execution Time

    Anyone,
    Is there an easy way to start a timer inside a SQL Plus script that shows exact run time at end of script completion?
    Right now I use the TIME option and have a time as the prompt start and then one at end but would like if the SQL Plus script could simply put a begin/end/run time for me as last output. TIMING is to much since I have many things execute and do not wnat to see every individual runtime.
    Thanks in advance,
    Miller

    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12047.htm#i2699704
    You can use TIMING with a named timer
    SQL> timing start script_time
    SQL> select 1 from dual;
             1
             1
    SQL> /
             1
             1
    SQL> /
             1
             1
    SQL> timing stop
    timing for: script_time
    Elapsed: 00:00:07.37
    SQL>

  • SQL*Plus Script Errors

    My scripts all contain relative file paths e.g.
    @@../directory1/file1.sql
    Is there a way of setting the current working directory in SQL Developer to make this work?
    In SQL*Plus for windows you simply opened the file but this does not seem to work.

    As I said, run them in SQL*Plus.
    SQL*Developer is a development tool and database browser, not a SQLPLus clone.
    It has its own methods of extracting data which may or may not suit your output requirements. You don't need col statements as much if you are viewing data in a grid, for example. [1]
    I don't know what you use the sqlplus scripts for, but they could be replaced over time with some combination of Apex, SQLDeveloper reports and straight sqldeveloper queries.
    As for SQL*PLus being greyed out on the menu, there are some known issues about that. I think one of them is that you need to be using tns connections. However, the sqlplus menu item is gone in sqldeveloper 1.5 so don't rely on it. Learn to run if from the command line.
    [1] Despite that, I would arguethat SQLDeveloper should support all (with tiny exceptions) SQLPlus commands. Not because I see it as a sqlplus replacement, but so it can be used to develop scripts which can then be run in SQL*Plus without amendment (without the hassle of switching back and forth during development)

  • How to control logic flow in SQL Plus script

    Hi
    I have the requirement below:
    Before I start running an SQL script, I need to ensure that I am connecting as a particular user. If I am not that user, then the script should show a msg "Error - Invalid User - Log in as <<username>>"
    Let's say i am executing a script A.sql.
    SQL > @<path>a.sql
    But before this script is executed -- i shall check for the user:
    block begins...
    select user into var1 from dual
    if upper(var1) != 'ABCUSER' then
    -- display the error message and stop execution of this script
    else
    @<path>a.sql (*it executes what i want :) )
    end if;
    block ends...
    How do I write this code using an SQL script ? Pls sugges

    Hi,
    As Centinul said, SQL*Plus is poorly equipped to deal with problems like this. If possible, try to do what you want outside of SQL*Plus.
    If you really have to do it in SQL*Plus, here are two ideas:
    (1) run a script conditionally
    (2) deliberately raise an error
    (1) Using SQL*Plus substitution variables, you can decide which of several scripts to run as a sub-script, based on the results of some query.
    For example, if a.sql is the script that only user ABCUSER is allowed to run, then write two other very short scripts:
    (a) warning.sql, such as the following:
    --  warning.sql
    PROMPT  You are not authorized to do this.
    QUIT(b) step_1.sql, which decides whether a.sql or warning.sql should be run, and does it:
    --     step_1.sql - Decide whether a.sql or warning.sql is to be run next, and do it.
    --     (a) decide:
    COLUMN  script_name_col     NEW_VALUE     script_name
    SELECT     CASE
              WHEN  USER = 'ABCUSER'
              THEN  'a.sql'
              ELSE  'warning.sql'
         END     AS script_name_col
    FROM     dual;
    --     do:
    @&script_nameYou may want to use @@, or specify a complete path name.
    (2) Deliberately raise an error, either in a separate script or in a.sql itself, like this:
    WHENEVER     SQLERROR     EXIT
    SELECT     CASE
              WHEN  USER = 'ABCUSER'
              THEN  NULL
              ELSE  TO_NUMBER ('This will raise ORA-01722')
         END     AS "Welcome!"
    FROM     dual;
    WHENEVER     SQLERROR     NONE
    -- continue with the original a.sql

  • Semicolon and / in SQL Plus scripts?

    Anyone,
    Seem to have some confusion over the use of / and ; inside PL SQL Scripts run in SQL Plus.
    I seem to get two commits thereby two rows on INSERT clase that has a ; and a /.
    i.e.
    /* Insert record into table for recording statistics on the runtime of this script */
    INSERT INTO MYTABLE ( col1, col2) VALUES ( value1, value2);
    COMMIT;
    /The above will get two of the same rows in the table. Is this an issue with SQL Plus settings? What do people typically use? I have a combination of SQL and DDL in my scripts and I need / for the DDL typically as I understand. How do othere intermix these and what standard is used.

    Dave, here are the very basics.
    The SQL language does not have command separators as only a single command at a time can be issued. Thus the following is invalid SQL:
    SELECT * FROM emp;
    The semicolon as command separator (or terminator) is not valid SQL. This is valid SQL:
    SELECT * FROM emp
    PL/SQL is a programming language similar to Pascal, C and Java. Multiple commands are used in a program. These need to be separated so that the parser/compiler can know where a command starts and where it ends. In PL/SQL the semicolon is used.
    The following is invalid PL/SQL as it is missing command separators:
    declare
    i integer
    begin
    i := 1234
    endThe following is valid PL/SQL :
    declare
    i integer;
    begin
    i := 1234;
    end;SQL*Plus is an Oracle CLI (command line interface) client. It can submit both SQL and PL/SQL to the database. It needs to know when you have stopped entering commands into its input buffer and to submit what you've entered to the database.
    SQL*Plus uses two characters for this. The semicolon and the forward slash. If you want to submit the above SELECT to Oracle using SQL*Plus, SQL*Plus needs to know when to submit its input buffer's content - thus:
    SQL> SELECT * FROM emp;
    Or:
    SQL> SELECT * FROM emp
    SQL> /
    When using PL/SQL in SQL*Plus, SQL*Plus "understands" that the semicolons you use are for the PL/SQL language - not an instruction from you to it to submit its buffer to Oracle for execution.
    The forward slash can also be at anytime used to resubmit the current SQL*Plus input buffer again. E.g.
    SQL> SELECT * FROM emp;
    .. now do the last SQL (or PL/SQL) in the buffer again
    SQL> /[i]

  • Set up SQL*plus client

    Hi Friends,
    I download oracle10g release 2 and create a test database. I can connect to database by server side SQL*plus.
    However, I install oracle client 10.2.01.0 in other mechine. I could not connect server.
    TNS as
    # This file is actually generated by netca. But if customers choose to
    # install "Software Only", this file wont exist and without the native
    # authentication, they will not be able to connect to the database on NT.
    #SQLNET.AUTHENTICATION_SERVICES = (NTS)
    #NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
    DS02 =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = jimmy.mycompany>COM)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME =orcl)
    how to fix it?
    I am new person in DBA.
    Thanks
    JIm

    On your server side do
    lsnrctl status
    what's the result?

  • Migrating SQL Plus Scripts to APEX

    Hi, all:
    I am trying to migrate some sql scripts which generates spool files as reports from sqlplus.
    I am trying to use APEX 4.2.1 interactive report pages to provide similar but much powerful functions.
    Database version 10.2.0.5.
    Seems Apex IR only accept SELECT .... queries for the region source.
    But the original scripts used in sqlplus do other things such as create a temporary table,
    then query based on this table and generate spool files.
    I would like to know is there way to simulate this table creation in APEX before handover
    the process to region source query to continue?
    I saw APEX sql workshop can create / save / run scripts, I guess somehow I need to call
    saved scripts to create temp tables before handover to IR page to do query.
    Any suggestions?
    Thanks,
    John

    You can indeed not use a temporary table. If you create and fill one in one process, there is no guarantee that the data you inserted will still be there at the moment the IR is rendered (the select against the temp table, in another process/region) due to the connection pooling apex uses. A collection would indeed be the only way. (A normal table does work of course)

  • Can network setting cause sql*plus logon failure?

    During install of verizon service the techs had to alter some network setting to allow the cable connection to work. Afterwards I was unable to connect to oracle database using pl*sql, getting instead an ORA 12514 error.
    Is it possible the altered network settings caused this problem? I am running oracle 10g on XP windows.

    1. you're not using pl*sql to connect. you're using SQLPLUS to connect.
    2. ORA-12514: TNS:listener could not resolve SERVICE_NAME given in connect descriptor
    so, verizon changed something, perhaps the "windows\system32\drivers\etc\hosts" file, so that now your TNSNAMES.ORA has the wrong info. check tnsnames.ora, and see if it's using machine name, IP, or "localhost", then give the new, correct info.

  • How to use bind vars in SQL*Plus Script?

    I am trying to use a bind var in my script ... does not seem to work ... something along these lines.
    variable v_id number;
    select max(user_id) into :v_id
    from user_id_tbl;
    exec trace_user(:v_id);
    This is in a UNIX Script - I don't get any errors but the binding is not working - not passing a valid v_id ... Any ideas?

    For the record a solution is:
    variable v_id number;
    begin
    select max(user_id) into :v_id from user_id_tbl;
    end;
    exec trace_user(:v_id);
    -- CJ

  • SQL*Plus column command not working with Script Runner

    SQL Developer EA 2.1
    When running a script (interactive or from a file), the COLUMN commands are ignored. The documentation (User's Guide 1.7.1) says that COLUMN is supported, but the headings set in the column command are not changed. As a test, the SET FEEDBACK OFF command is processed.
    SET FEEDBACK OFF
    COLUMN ename HEADING 'Name'
    COLUMN job HEADING 'Job'
    COLUMN deptno HEADING 'Dept'
    SELECT ename as ename, JOB, DEPTNO
    FROM EMPLOYEES;
    The documentation for Script Runner (User's Guide 1.7.2) says that a much more limited set of SQL*Plus commands are available.
    Is this intended behavior? If so, the documentation should reflect that the COLUMN command is ignored.

    Hi,
    Doc bug logged:
    Bug 9015160 - OTNEA1: USER GUIDE COLUMN SUPPORTS 'COLUMN...NEWVAL' ONLY
    The user guide says column is supported, but
    Column supports the following new_value use only
    i.e. moving a value from a selected column to a substitution variable:
    column aval new_v a
    select 1 aval from dual;
    select '&a' || ' is 1' from dual;
    Output:
    AVAL
    1
    1 rows selected
    '1'||'IS1'
    1 is 1
    1 rows selected
    -Turloch

Maybe you are looking for

  • HTM & HTML ext

    Groupers I have the site that been designed with DW8. the extentions of the file including my home page is HTML. I am now trying to load the site to my remote server(host) but the host have their RULES. the HOME PAGE must have the name & extention in

  • HP Photosmart Premium All-in-One Printer --reverts to offline mode and can't get back online

    What is the quickest, easiest way to get the printer back online?   There seems to be no way to get it back online.  I'm using Windows Vista OS.  Printer is running on wireless network (2wire).   Appreciate a quick resolution. Thanks!

  • Mail app crashes at launch

    Hi, I've read through some of the posts and haven't found anything that will help. I have 3 Macs (Mac Pro, MacBook Pro, and G5 PowerPC), all running Leopard 10.5.2, and when I tried to boot the Mail app today on the Mac Pro, it just crashed at launch

  • Symbol at end of file name prevents email recipient from opening PDF

    The special symbol looks like: ˥  However, there is a tiny little arrow that is on the end of the horizontal part that points left. It is located immediately after the file name, but before the .extension. I have been sending out resumes and the ones

  • Got a SONY mp3 player for Christmas: How do I sync with iTunes?

    OK, here's the deal. I have a MacBook Pro and use iTunes regularly, but now I have a SONY mp3 player from Santa. How do I get my songs from iTunes onto my SONY? Someone help. Thanks!