Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
849 views
in Technique[技术] by (71.8m points)

c# - Why Do I get OutOfRange Exception in GetOrdinal Function of this CLOB field?

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();
}

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. Could it be that my SELECT statement is problematic? I have been taking code from different references.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
            }

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...