Forum Stats

  • 3,872,498 Users
  • 2,266,434 Discussions
  • 7,911,226 Comments

Discussions

How can you specify the output character set for sqlcl ?

Fpons-Oracle
Fpons-Oracle Member Posts: 1 Employee

Unlike SQL*Plus, sqlcl does not follow NLS_LANG. Suppose you want to select a string from a database in AL32UTF8 and display it in, say, a Windows 10 Command Prompt window using WE8PC850 as character set. How do you tell the Oracle Net layer within sqlcl to adapt to gthe client character set ?

Answers

  • User_H3J7U
    User_H3J7U Member Posts: 1,062 Gold Trophy

    Java uses UTF-16 only, setting client charset is not needed to interact with database. But the java application needs the proper encoding to interact with console.

    SQLcl uses NLS_LANG to set the language, territory in database and encoding for own output (set encoding). SQLcl does not know the AL32UTF8 encoding and displays the INFO. You can ignore this message or use deprecated UTF8 client charset (for only SQLcl). NLS_LANG can also be used in thick mode/OCI.

    Change the console encoding to 65001 and set the appropriate font. The SQLcl command set encoding doesn't seem to be working, use environment variable JAVA_TOOL_OPTIONS.

    D:\>chcp 65001
    Active code page: 65001
    D:\>set NLS_LANG=.al32utf8
    D:\>set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
    D:\>sql -s [email protected]
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    Ianuarius 10, 2022 3:16:59 PM oracle.dbtools.raptor.scriptrunner.cmdline.SQLCliOptions processNLSLANG
    INFO: NLS_LANG is set, but not valid. Ignoring.
    
    SQL> select sys_context('userenv','language') nls_lang, chars, dump(chars, 1016) dump_chars
      2* from (select 'Ω①₿½¼' chars from dual);
    
      NLS_LANG    CHARS                                                               DUMP_CHARS
    __________ ________ ________________________________________________________________________
    _.AL32UTF8 Ω①₿½¼    Typ=96 Len=12 CharacterSet=AL32UTF8: ce,a9,e2,91,a0,e2,82,bf,c2,bd,c2,bc
    
    SQL> exit
    
    D:\>chcp 850
    Active code page: 850
    D:\>set NLS_LANG=.we8pc850
    D:\>set JAVA_TOOL_OPTIONS=-Dfile.encoding=IBM850
    D:\>sql -s [email protected]
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=IBM850
    SQL> select sys_context('userenv','language') nls_lang, chars, dump(chars, 1016) dump_chars
      2* from (select 'Ω①₿½¼' chars from dual);
    
      NLS_LANG    CHARS                                                               DUMP_CHARS
    __________ ________ ________________________________________________________________________
    _.AL32UTF8 ???½¼    Typ=96 Len=12 CharacterSet=AL32UTF8: ce,a9,e2,91,a0,e2,82,bf,c2,bd,c2,bc