问题
I am trying to execute a PL-SQL block in c# using System.Data.OrcaleClient
.
The PL-SQL block when executed in oracle, prints the result using dbms.ouput
.
I want to get that "dbms.ouput
" result in my C# code.
Please help.
回答1:
Try to use get_line
function of dbms_output
package. You can create a procedure to return the output. Something like this (just a example):
procedure call_with_output(p_output out varchar2) is
vret integer := 0;
vtxt varchar2(4000);
begin
dbms_output.enable;
-- here call code that generate lines
-- use the loop to retrieve info
while vret = 0 loop
dbms_output.get_line(vtxt, vret);
if vret = 0 then
if p_output is null then
p_output := vtxt;
else
p_output := p_output || chr(10) || vtxt;
end if;
end if;
end loop;
dbms_output.disable;
end;
回答2:
I am using the next method:
private string GetDbmsOutputLine()
{
OracleCommand command = new OracleCommand
{
Connection = <connection>,
CommandText = "begin dbms_output.get_line(:line, :status); end;",
CommandType = CommandType.Text
};
OracleParameter lineParameter = new OracleParameter("line",
OracleType.VarChar);
lineParameter.Size = 32000;
lineParameter.Direction = ParameterDirection.Output;
command.Parameters.Add(lineParameter);
OracleParameter statusParameter = new OracleParameter("status",
OracleType.Int32);
statusParameter.Direction = ParameterDirection.Output;
command.Parameters.Add(statusParameter);
command.ExecuteNonQuery();
if (command.Parameters["line"].Value is DBNull)
return null;
string line = command.Parameters["line"].Value as string;
return line;
}
Call it several times to get multistring value because there are problems with calling dbms_output.get_lines with System.Data.OracleClient.
来源:https://stackoverflow.com/questions/9545389/how-to-get-the-dbms-output-value-returned-by-a-pl-sql-block-in-c-sharp