【问题标题】:Getting output from DBMS_OUTPUT.GET_LINES() using c#使用 c# 从 DBMS_OUTPUT.GET_LINES() 获取输出
【发布时间】:2014-07-10 01:48:22
【问题描述】:

我知道如何从 DBMS_OUTPUT.GET_LINE() 获取输出。

您可以参考http://oradim.blogspot.com.tr/2007/05/odpnet-tip-retrieving-dbmsoutput-text.html

在此页面上获取输出形式 DBMS_OUTPUT.GET_LINES() 方法也使用 ODP.Net 进行了解释。有没有办法只使用 ADO.NET 来管理它。

例如,我如何从下面读取所有输出

begin 
 declare 
   stage number := 0; 
   begin
    DBMS_OUTPUT.PUT_LINE('STARTING:'); 
    INSERT INTO Country ( code, name) VALUES (1 , 'xxxx');
    INSERT INTO City ( code, name) VALUES (1 , 'yyyy');
    DBMS_OUTPUT.PUT_LINE('DONE:'); 
COMMIT; 

EXCEPTION  -- exception handlers begin 
  WHEN OTHERS THEN  -- handles all other errors 
   DBMS_OUTPUT.PUT_LINE('Error occured, rollback...');  
   DBMS_OUTPUT.get_LINE(:1, :2);
   stage := -1;
   ROLLBACK; 
  end;
end; 

输出应该是这样的:

STARTING
DONE

我有这个代码块,但它只返回第一个输出行

using (OracleCommand cmd = cnn.CreateCommand())
{
    OracleParameter status = new OracleParameter(":1", OracleType.VarChar, 32000);
    p_line.Direction = ParameterDirection.Output;

    OracleParameter line = new OracleParameter(":2", OracleType.Double);
    p_status.Direction = ParameterDirection.Output;  

    cmd.CommandText = script;
    cmd.CommandType = CommandType.Text;
    cmd.Parameters.Add(status);
    cmd.Parameters.Add(line );
    cmd.ExecuteNonQuery();

    string status = status.Value.ToString();
    string line = line.Value.ToString();
}

输出:

STARTING

【问题讨论】:

    标签: c# sql oracle plsql ado.net


    【解决方案1】:

    DBMS_OUTPUT.GET_LINE 只返回缓冲区的第一行(并删除它)。如果您使用此方法,则需要为每一行调用一次。如果没有可用的行,则返回状态为 1。

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 2020-08-24
      • 1970-01-01
      • 1970-01-01
      • 2011-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-06-07
      • 2015-12-09
      相关资源
      最近更新 更多