1

我正在尝试将 XML 类型传递给 Oracle 9i 中的存储过程。它应该做的就是从节点中提取一个值并返回它,但它不是返回值。任何人都可以建议吗?

XMLString = "<?xml version='1.0' encoding='utf-8' ?>";
XMLString += "<Document>";
XMLString += "<DocumentType>WorkOrder</DocumentType>";
XMLString += "<DocumentAction>Create</DocumentAction>";
XMLString += "<WorkOrder>";
XMLString += "<WO>123456</WO>";
XMLString += "<WOTask>1</WOTask>";
XMLString += "</WorkOrder>";
XMLString += "</Document>";

oraCon.ConnectionString = s_connectionString;
oraCon.Open();
oraCommand.CommandType = CommandType.StoredProcedure;
oraCommand.CommandText = "LOUISETEST.GetActionType";
oraCommand.Connection = oraCon;
oraCommand.Parameters.Add("xml_document_i", OracleDbType.XmlType, XMLString, ParameterDirection.Input);
oraCommand.Parameters.Add("action_i", OracleDbType.Varchar2, result, ParameterDirection.Output);
oraCommand.ExecuteNonQuery();

Console.WriteLine("Result : "+result.ToString());

存储过程如下:

  PROCEDURE GetActionType       
    (
    xml_document_i        IN XMLTYPE
    ,action_i          OUT VARCHAR2
    )
     AS
  BEGIN
      SELECT xml_document_i.Extract('/DocumentAction/text()').getstringval() INTO action_i
      FROM TABLE (XMLSEQUENCE (xml_document_i.EXTRACT ('/Document') ) ) ;
  END GetActionType;
4

1 回答 1

1

我通过以下方式解决了这个问题:

            //XMLString = "<?xml version='1.0' encoding='utf-8' ?>";
            XMLString += "<Document>";
            XMLString += "<DocumentType>WO</DocumentType>";
            XMLString += "<DocumentAction>Create</DocumentAction>";
            XMLString += "<WorkOrder>";
            XMLString += "<WO>123456</WO>";
            XMLString += "<WOTask>1</WOTask>";
            XMLString += "</WorkOrder>";
            XMLString += "</Document>";

            Console.WriteLine(XMLString.ToString());

            oraCon.ConnectionString = s_connectionString;
            oraCon.Open();
            oraCommand.CommandType = CommandType.StoredProcedure;
            oraCommand.CommandText = "LOUISETEST.GetActionType";
            oraCommand.Connection = oraCon;
            oraCommand.Parameters.Add("xml_document_i", OracleDbType.XmlType, XMLString, ParameterDirection.Input);

            OracleParameter result = new OracleParameter();
            result.ParameterName = "action_i";
            result.Direction = ParameterDirection.Output;
            result.OracleDbType = OracleDbType.Varchar2;
            result.Size = 256;
            oraCommand.Parameters.Add(result);

            oraCommand.ExecuteNonQuery();

            Console.WriteLine("Result : " + result.Value.ToString());

并使用以下 SP:

PROCEDURE GetActionType        
    ( 
    xml_document_i        IN XMLTYPE
    ,action_i             OUT VARCHAR2
    ) 
     AS 
     v_name      VARCHAR2(256);
  BEGIN   

  v_name := xml_document_i.extract('/Document/DocumentAction/text()').getStringVal();    
  SELECT v_name INTO action_i FROM dual;

  END GetActionType; 
于 2012-10-09T15:40:22.023 回答