1

Oracle 9i のストアド プロシージャに XML 型を渡そうとしています。ノードから値を抽出して返すことだけが想定されていますが、値を返すことはありません。誰でもアドバイスできますか?

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 に答える