使用ADODB.RecordSet(MS ActiveX数据对象2.8库)在Excel电子表格上显示Clob字段(Oracle)的西里尔字母时,我们遇到了问题。
作为示例,我创建了一个带有Clob字段的表。我只用西里尔字母插入了一行,并试图在Excel电子表格上显示该值。但是,文本显示为????在Msgbox和单元格中。仅在从Clob字段获取值时才会发生这种情况。如果我们从varchar查询它们,效果很好。我试过11.2.0.2.0和12.2.0.1.0。行为是相同的。为了解决这个问题,我们该怎么办?
db中的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
答案 0 :(得分:2)
将您的NLS_LANG
值设置为支持西里尔字母的字符集,例如CL8MSWIN1251
或AL32UTF8
。
例如,您可以通过环境变量来完成此操作
SET NLS_LANG=AMERICAN_RUSSIA.CL8MSWIN1251
或在您的注册表HKLM\SOFTWARE\Wow6432Node\ORACLE\KEY_%ORACLE_HOME_NAME%\NLS_LANG
(32位)中。 HKLM\SOFTWARE\ORACLE\KEY_%ORACLE_HOME_NAME%\NLS_LANG
(用于64位)。