Search code examples
oracle-databaseutf-8sqlplus

Set charset to UTF-8 in SQL*Plus


I have a SQL script that contains the following statement:

insert into employee(fname,lname) values('Jörg','Müller');

My Database Charset ist set to AL32UTF8 but when I execute the script in SQLPlus the german letters Ö and Ü are not saved correctly. How can I set the Charset of SQLPlus to UTF-8?

Is it possible to set the SQL*Plus Charset to UTF-8 in my script file (the sql script file contains the command to set the charset to UTF-8)?

My runtime environment is Window but script should also be able to run on unix. My oracle version is 19c.


Solution

  • SQL*Plus inherits the character set from cmd window. You need to set encoding to UTF-8 and tell it Oracle. This is done by NLS_LANG parameter.

    Try this:

    chcp 65001
    set NLS_LANG=.AL32UTF8
    sqlplus ....
    

    Of course, this works only if your sql-file is also saved as UTF-8. Otherwise you need to adapt character sets from above.

    See OdbcConnection returning Chinese Characters as "?"