如何使用 OleDb 在 Oracle 中读取 CLOB 列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2537613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:18:18  来源:igfitidea点击:

How to read a CLOB column in Oracle using OleDb?

.netoracleoledbclob

提问by Thibault Falise

I have created a table on an Oracle 10g database with this structure :

我在具有以下结构的 Oracle 10g 数据库上创建了一个表:

create table myTable
(
id       number(32,0)      primary key,
myData   clob
)

I can insert rows in the table without any problem, but when I try to read data from the table using OleDb connection, I get an exception.

我可以毫无问题地在表中插入行,但是当我尝试使用 OleDb 连接从表中读取数据时,出现异常。

Here is the code I use :

这是我使用的代码:

using (OleDbConnection dbConnection = new OleDbConnection("ConnectionString"))
{
    dbConnection.Open();

    OleDbCommand dbCommand = dbConnection.CreateCommand();

    dbCommand.CommandText = "SELECT * FROM myTable WHERE id=?";
    dbCommand.Parameters.AddWithValue("ID", id);

    OleDbDataReader dbReader = dbCommand.ExecuteReader();
}

The exception details seems to point on an unsupported data type :

异常详细信息似乎指向不受支持的数据类型:

System.Data.OleDb.OleDbException: 
Unspecified error Oracle error occurred, but error message could not be retrieved from Oracle. 
Data type is not supported.

Does anyone know how I can read this data using the OleDb connection ?

有谁知道我如何使用 OleDb 连接读取这些数据?

PS : The driver used in this case is the Microsoft one.

PS:本例中使用的驱动程序是微软的。

采纳答案by Colin Pickard

I'm not sure it is possible to use the CLOB type with the Microsoft OLEDB driver.

我不确定是否可以将 CLOB 类型与 Microsoft OLEDB 驱动程序一起使用。

Do you have to use the Microsoft one? You would be much better to use the Oracle Provider for OLE DBor better yet just use Oracle Data Provider for .NET(ODP.NET).

你必须使用微软的吗?您最好使用适用于 OLE DBOracle 提供程序,或者更好地使用适用于 .NET 的 Oracle 数据提供程序(ODP.NET)。