我在使用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;
要在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();
如何使用上述Oracle流程/过程发送XML并将输出检索为XML。
谢谢
答案 0 :(得分: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;
在您的代码中,没有一个绑定参数,然后OracleParameter
从未使用过。如果你想在pl / sql代码中使用out参数,你不应该在声明中声明它,而是使用冒号和#34;:&#34; -
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);
}