4

I have a batch file that execute SQL scripts through sqlplus:

(
   echo @"./myUTF8.sql"
   echo @"./myAnsi.sql"
) | sqlplus uset/pwd@mybd

Unfortunately these SQL scripts are generated in different encoding, Ansi, UTF8, ...

How can I tell sqlplus that a script is of a specified encoding?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1753180
  • 87
  • 1
  • 1
  • 7

3 Answers3

7

You have to change encoding with command chcp, e.g. chcp 65001 for UTF-8 or chcp 1252 for Windows 1252. Term "ANSI" is just a general name for many different encodings. See column "ANSI codepage" at this National Language Support (NLS) API Reference to get codepage for you locale.

If you have to change the encoding inside a SQL script use host chcp ...

However, you also have to set NLS_LANG environment variable accordingly. So after you have changed codepage you must also run for example SET NLS_LANG=.AL32UTF8 or SET NLS_LANG=.WE8MSWIN1252.

See OdbcConnection returning Chinese Characters as "?" for more details.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
7

I have a SQL script created in UTF8, to run it with sqlplus in Linux, before open sqlplus do

export NLS_LANG=.AL32UTF8

then use sqlplus to load the script.

beaver
  • 523
  • 1
  • 9
  • 20
Feng Zhang
  • 1,698
  • 1
  • 17
  • 20
0

sqlplus 19.x / windows 10 / command prompt

Setting "host chcp 65001" in the sql script itself does not help, nor in a "set_sqlplus_params.sql" called before the sql script to execute.

The only help was to set it as environment variable in the shell itself:

set SET NLS_LANG=.AL32UTF8

and then call sqlplus for executing the script in UTF-8.

Heri
  • 4,368
  • 1
  • 31
  • 51