sql - How to fix character encoding in sql query
问题描述
I have a db2 database where I store names containing special characters. When I try to retrieve them with an internal software, I get proper results. However when I tried to do the same with queries or look into the db, the characters are stored strangely.
The documentation says that the encoding is utf-8 latin1. My query looks something like this:
SELECT firstn, lastn
FROM unams
WHERE unamid = 12345
The user with the given ID has some special characters in his/her name: é and ó, but the query returns it as Ă© and Ăł.
Is there a way to convert the characters back to their original form with using some simple SQL function? I am new to databases and encoding, trying to understand the latter by reading this but I'm quite lost.
EDIT: Currently sending queries via SPSS Modeler with a proper ODBC driver, the database lies on a Windows Server 2016
解决方案
Per the comments, the solution was to create a Windows environment variable DB2CODEPAGE=1208 , then restart, then drop and re-populate the tables.
If the applications runs locally on the Db2-server (i.e. only one hostname is involved) then the same variable can be set. This will impact all local applications that use the UTF-8 encoded database.
If the application runs remotely from the Db2-server (i.e. two hostnames are involved) then set the variable on the workstation and on the Windows Db2-server.
Current versions of IBM supplied Db2-clients on Windows will derive their codepage from the regional settings which might not always render Unicode characters correctly, so using the DB2CODEPAGE=1208 forces the Db2-client CLI drivers to use a Unicode application code page to override this.
推荐阅读
- javascript - javascript对象中的重复键
- azure - Azure Functions 的复杂性级别/责任
- laravel - Laravel Lumen 到 Google App Engine 的有效缓存路径问题
- mysql - React Native 使用 axios 返回源获取数据过早耗尽
- node.js - 我可以从其他电子邮件提供商发送 Firebase 验证电子邮件吗?
- reporting-services - 有条件地格式化 tablix 的某些单元格
- regex - 使用正则表达式选择字符的第二个实例
- reactjs - BrowserRouter 没有重定向到 basename (react-router-dom@5.1.2)
- c# - 当我在 WinForms 应用程序上使用 DefaultProxy 时有效,但在 WCF 中无效?
- php - 如何过滤laravel中的关系属性