本文介绍了我为什么会在这个CLOB字段的GetOrdinal功能OutOfRange异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码的样本。本场FUNCTION_SCRIPT是在我的表IS_FUNCTION一个CLOB字段(仅CLOB字段)

This is the sample of my code. The field FUNCTION_SCRIPT is a CLOB field (the only CLOB field) in my table IS_FUNCTION

public void ReadFunction(string FName, out string fContent) {
    OracleCommand command = _connection.CreateCommand();
    OracleTransaction transaction = _connection.BeginTransaction();
    command.Transaction = transaction;
    command.CommandText = "SELECT TO_CLOB(TO_NCLOB(FUNCTION_SCRIPT)) FROM IS_FUNCTION where FNAME=:fName ";
    command.Parameters.Add("FName", OracleType.NVarChar).Value = FName;
    OracleDataReader odr = command.ExecuteReader();
    int temp = odr.GetOrdinal("FUNCTION_SCRIPT");
    OracleLob myLob = odr.GetOracleLob(temp);
    fContent = (String)myLob.Value;
    odr.close();
}



我得到一个超出范围的异常时, TEMP = odr.GetOrdinal(FUNCTION_SCRIPT)语句被执行。不知道为什么?我一直在想现在读几个小时,这个CLOB字段。这是我来最接近的一次。您的帮助将非常感激。

I get an out of range exception when temp = odr.GetOrdinal("FUNCTION_SCRIPT") statement is executed. Have no idea why? I have been trying to read this CLOB field for few hours now. This is the closest I have come. Your help would be highly appreciated.

P.S。难道说我的SELECT语句是有问题的?我已经从不同的参考服用代码。

p.s. Could it be that my SELECT statement is problematic? I have been taking code from different references.

推荐答案

感谢所有的建议和帮助。我发现我的问题是由添加

Thanks for all the suggestions and helps. I found that my problem was resolved by adding a

 if(odr.Read())
            {
                int temp = odr.GetOrdinal("FUNCTION_SCRIPT");
                OracleLob myLob = odr.GetOracleLob(temp);
                fContent = (String)myLob.Value;
            }

在换句话说,我缺少的声明odr.Read给ExecuteReader后( )语句。

In other words, I was missing the statement odr.Read after the ExecuteReader() statement.

这篇关于我为什么会在这个CLOB字段的GetOrdinal功能OutOfRange异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:39