来自 Oracle 的 VBA 中显示为问号的西里尔字母

Cyrillic letter displaying as question marks in VBA from Oracle

我们在使用 ADODB.RecordSet(MS ActiveX 数据对象 2.8 库)的 Excel 电子表格中显示来自 Clob 字段 (Oracle) 的西里尔字母时遇到问题。

例如,我创建了一个带有一个 Clob 字段的 table。我只插入了一行西里尔字母,并试图在 Excel 电子表格中显示该值。但是,文本显示为 ?????在 Msgbox 和单元格中。只有在从 Clob 字段获取值时才会发生这种情况。如果我们从 varchar 查询它们,它工作正常。我试过 11.2.0.2.0 和 12.2.0.1.0。行为是一样的。我们可以做些什么来解决这个问题?

NLS_CHARACTERSET 在数据库中是 AL32UTF8.

VBA代码如下:

Private Sub UnloadReportBtn_Click()
    Dim RecordSet As ADODB.RecordSet

    Set RecordSet = getTestClob

    While RecordSet.EOF = False
        MsgBox RecordSet.Fields("TEST1")

        Cells(7, 7) = RecordSet.Fields("TEST1")

        RecordSet.MoveNext
    Wend
End Sub

Public Function getTestClob()
    Dim Query As String

    Query = "SELECT TEST1 FROM TEST_CLOB"

    Set getTestClob = getRecordSet(Query)
End Function

Public Function getRecordSet(Query As String) As ADODB.RecordSet
    Dim SQLCommand As ADODB.Command

    Dim RecordSet As ADODB.RecordSet

    Set SQLCommand = New ADODB.Command
    Set SQLCommand.ActiveConnection = Connection

    SQLCommand.CommandText = Query
    SQLCommand.CommandType = adCmdText
    SQLCommand.CommandTimeout = 0

    Set getRecordSet = SQLCommand.execute
End Function

将您的 NLS_LANG 值设置为支持西里尔字符的字符集,例如CL8MSWIN1251AL32UTF8.

你可以通过环境变量来做到这一点,例如

SET NLS_LANG=AMERICAN_RUSSIA.CL8MSWIN1251

或在 HKLM\SOFTWARE\Wow6432Node\ORACLE\KEY_%ORACLE_HOME_NAME%\NLS_LANG 的注册表中(对于 32 位),resp。 HKLM\SOFTWARE\ORACLE\KEY_%ORACLE_HOME_NAME%\NLS_LANG 64 位。

有关详细信息,另请参阅