如何在c#中引入Oracle存储过程的XML输出

时间:2023-02-03 16:37:12

I am facing issues to use Oracle with C#. We are moving away from SQL to Oracle and our S/W vendor provide us APIusing the AX_Gate.Process method, to return trading styles via a PL/SQL anonymous block:

我正面临使用Oracle和C#的问题。我们正在从SQL转向Oracle,我们的S / W供应商为我们提供了使用AX_Gate.Process方法的API,通过PL / SQL匿名块返回交易风格:

declare
  vMName varchar2(100);
  vInput XMLtype;
  vOutput XMLtype;
begin
  vMName := 'Marketing Styles';
  vInput := XMLtype('<Marketing_Styles-Read/>');
  vOutput := AX_Gate.Process(vMethodName, vInput);
  DBMS_OUTPUT.PUT_LINE(vOutput.getStringVal());
end;

To use this process in C# i develope code that is able to send information but it is not sending back the required XML output. C# code is below:

要在C#i中使用此过程,请开发能够发送信息的代码,但不会发回所需的XML输出。 C#代码如下:

try
            {
                //Oracle connection open
                OracleConnection.Open();

                //SQL script to invoke  AX_Gate.Process
                string SQLScript = "declare vMName varchar2(100); vInput XMLtype; vOutput XMLtype; "+
                                   "begin vOutput := AX_Gate.Process(" + vMethodName + " , " + vInput + ");  end;";

                OracleCommand OraCommand = new OracleCommand(SQLScript);
                OraCommand.Connection = OracleConnection;
                OraCommand.CommandType = System.Data.CommandType.Text;
                //OraCommand.Parameters.Add(new OracleParameter("vOutput", OracleDbType.XmlType, ParameterDirection.Output));
                OraCommand.Parameters.Add(new OracleParameter("vOutput", OracleDbType.XmlType)).Direction = ParameterDirection.Output;

                //OracleDataReader dr = new OracleDataReader();
                OracleXmlType poXml;
                OracleDataReader poReader = OraCommand.ExecuteReader();



                var sqlDataAdapter = new OracleDataAdapter(OraCommand);
                var dataTable = new DataTable("vOutput");
                sqlDataAdapter.Fill(dataTable);
                OracleConnection.Close();

How can I send XML and retrieve back output as an XML using above Oracle process / procedure.

如何使用上述Oracle进程/过程发送XML并将输出检索为XML。

Thank You

1 个解决方案

#1


0  

        string SQLScript = "declare vMName varchar2(100); vInput XMLtype; vOutput XMLtype; "+
                           "begin vOutput := AX_Gate.Process(" + vMethodName + " , " + vInput + ");  end;";
...
OraCommand.Parameters.Add(new OracleParameter("vOutput", OracleDbType.XmlType)).Direction = ParameterDirection.Output;

In your code there is not one bind paramter and then OracleParameter never used. If you want to use out parameter in pl/sql code, you should not to declare it in declaration, but use it with colon sign ":" -

在您的代码中没有一个绑定参数,然后OracleParameter从未使用过。如果你想在pl / sql代码中使用out参数,你不应该在声明中声明它,而是使用冒号“:” -

    String queryString =
        @"declare
             xml_ xmltype := xmltype('<root></root>');
            begin
             :par := xml_;
            end;";

    using (OracleConnection connection = new OracleConnection(source))
    {
        OracleCommand command = new OracleCommand(queryString, connection);
        connection.Open();
        var res = command.Parameters.Add("par", OracleDbType.XmlType, ParameterDirection.Output);
        command.ExecuteNonQuery();
        MessageBox.Show(((Oracle.DataAccess.Types.OracleXmlType)(res.Value)).Value);
    }

#1


0  

        string SQLScript = "declare vMName varchar2(100); vInput XMLtype; vOutput XMLtype; "+
                           "begin vOutput := AX_Gate.Process(" + vMethodName + " , " + vInput + ");  end;";
...
OraCommand.Parameters.Add(new OracleParameter("vOutput", OracleDbType.XmlType)).Direction = ParameterDirection.Output;

In your code there is not one bind paramter and then OracleParameter never used. If you want to use out parameter in pl/sql code, you should not to declare it in declaration, but use it with colon sign ":" -

在您的代码中没有一个绑定参数,然后OracleParameter从未使用过。如果你想在pl / sql代码中使用out参数,你不应该在声明中声明它,而是使用冒号“:” -

    String queryString =
        @"declare
             xml_ xmltype := xmltype('<root></root>');
            begin
             :par := xml_;
            end;";

    using (OracleConnection connection = new OracleConnection(source))
    {
        OracleCommand command = new OracleCommand(queryString, connection);
        connection.Open();
        var res = command.Parameters.Add("par", OracleDbType.XmlType, ParameterDirection.Output);
        command.ExecuteNonQuery();
        MessageBox.Show(((Oracle.DataAccess.Types.OracleXmlType)(res.Value)).Value);
    }