Oracle 9i存储过程XML类型输入参数

时间:2012-10-09 09:46:18

标签: c# stored-procedures oracle9i

我正在尝试将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;

1 个答案:

答案 0 :(得分: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;