使用Oracle.ManagedDataAccess.Client请求XMLType时出现TTC错误

时间:2014-10-17 10:08:59

标签: odp.net oracle12c

我在.Net应用程序中使用带有ODAC的oracle12c数据库

这2个查询在sqldevelopper中工作:

SELECT * 
FROM TABLE_A 
WHERE (XMLCAST(XMLQUERY('/*/name' PASSING TABLE_A.XML_VALUE RETURNING CONTENT) AS NVARCHAR(225)) = 'admin')

SELECT * 
FROM TABLE_A 
WHERE (XMLCAST(XMLQUERY('count(/*)' PASSING TABLE_A.XML_VALUE RETURNING CONTENT) AS NUMBER) = 1)

但是当我通过Oracle.ManagedDataAccess.Client请求时,我对这些查询有TTC错误,尽管此查询有效:

SELECT * 
FROM TABLE_A 
WHERE (XMLCAST(TABLE_A.XML_VALUE.extract('/*/name') AS NVARCHAR(225)) = 'admin')

在Christian Shay评论之后编辑

我真的没有选择SELECT * 我命名TABLE_A的所有字段并获取xmltype字段:

TABLE_A.XML_VALUE.getStringVal()

第二次修改 错误消息不明确,仅为:TTC错误 没有InnerException StackTrace是:

 à OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int64 initialLOBFetchSize, Int64[] scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Int64[]& rowsAffectedByArrayBind, Boolean bDefineDone, Boolean& bMoreThanOneRowAffectedByDmlWithRetClause, Boolean bLOBArrayFetchRequired)
   à OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, Boolean isDescribeOnly, Boolean isFromEF)
   à Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
   à Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)
   à System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()

经过调查,问题是由sql参数引起的。 此查询在TTC错误中失败:

SELECT TABLE_A.XML_VALUE.GetStringVal() 
    FROM TABLE_A 
    WHERE (XMLCAST(XMLQUERY('count(/*)' PASSING TABLE_A.XML_VALUE RETURNING CONTENT) AS NUMBER) = :Criterion0)

但是,如果我将sql参数:Criterion0替换为值1,则查询将起作用

单元测试

Oracle.DataAccess.dll的版本:4.121.1.0 ODAC RELEASE 3 BETA 脚本sql:

CREATE TABLE XMLTEST
(
    ID NUMBER (10) NOT NULL,
    XML_VALUE XMLTYPE
);
INSERT INTO XMLTEST (ID,XML_VALUE) VALUES (1,XMLType('<root><data>TEST1</data><data>TEST2</data></root>'));

测试方法:

[TestMethod]
public void ParameterOnXMLTypeTest()
{
    string connectionString = "User ID=troopers;Password=troopers;Data Source=MYTST;";
    Oracle.ManagedDataAccess.Client.OracleConnection connection = new Oracle.ManagedDataAccess.Client.OracleConnection(connectionString);
    Oracle.ManagedDataAccess.Client.OracleParameter parameter = new Oracle.ManagedDataAccess.Client.OracleParameter("Param1", 2);
    string query = "SELECT XMLTEST.ID FROM XMLTEST WHERE XMLCAST(XMLQUERY('count(/*/*)' PASSING XMLTEST.XML_VALUE RETURNING CONTENT) AS NUMBER) = :Param1";
    Oracle.ManagedDataAccess.Client.OracleCommand command = new Oracle.ManagedDataAccess.Client.OracleCommand(query, connection);
    command.Parameters.Add(parameter);
    connection.Open();
    using(IDataReader reader = command.ExecuteReader())
    {
        Assert.IsTrue(reader.Read());
        Assert.AreEqual(1, reader.GetInt32(reader.GetOrdinal("ID")));
        Assert.IsFalse(reader.Read());
    }
    connection.Close();
}

1 个答案:

答案 0 :(得分:0)

在撰写本文时,ODP.NET完全托管驱动程序目前不支持XMLType。这将在未来的版本中发生变化。

http://docs.oracle.com/html/E41125_02/intro004.htm