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
  • 704,970
  • 168
  • 1,303
  • 1,425
user1753180
  • 87
  • 1
  • 1
  • 7

2 Answers2

6

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
  • 497
  • 1
  • 10
  • 17
Feng Zhang
  • 1,232
  • 1
  • 12
  • 18
5

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.

Community
  • 1
  • 1
Wernfried Domscheit
  • 46,769
  • 7
  • 65
  • 91