2012-03-03 1 views
1

System.Data.OrcaleClient을 사용하여 C#에서 PL-SQL 블록을 실행하려고합니다. PL-SQL 블록을 oracle에서 실행하면 dbms.ouput을 사용하여 결과를 인쇄합니다.C#에서 PL-SQL 블록에 의해 반환 된 dbms.output 값을 얻는 방법

나는 "dbms.ouput"결과를 내 C# 코드에 넣고 싶습니다.

도와주세요.

+0

왜 [기능] (http://www.techonthenet.com/oracle/functions.php)으로 차단하고 결과를 _ 반환 하시겠습니까? – Ben

+0

안녕 벤, 우리는 제 3 자와 통합하고 그들은 PL-SQL 블록을 우리에게 제공하여 필요한 결과를 얻었습니다. – Dinu

답변

4

패키지의 get_line 기능을 사용해보십시오. 출력을 리턴하는 프로 시저를 작성할 수 있습니다. 이 (단지 예)처럼 뭔가 :

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; 
+0

나는 당신의 솔루션을 좋아합니다. 이것은 서버에 대한 단일 호출과 함께'get_lines' 대신에'get_line'을 사용하는 단순성을 결합합니다. 내가 해왔 던 대답은 ODP.NET을 통해'get_lines '를 호출하는 것과 관련이 있습니다. 이것은 어리석은 생각입니다. +1 –

+1

+1 그러나 총 출력량이 32k 이하인 경우에만 작동합니다. 아마도 그럴 것이지만 루프에서 생성하는 경우 디버그 출력을 얻을 수 있습니다. dbms_output에 출력됩니다. –

+0

32K를 얻으려면 vtxt의 선언을'vtxt varcahr2 (32767)' –

1

내가 다음 방법을 사용하고 있습니다 : 시스템과 dbms_output.get_lines를 호출에 문제가 있기 때문에

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; 
    } 

전화 여러 번 값을 멀티 스트링 얻을 수 있습니다. Data.OracleClient.

관련 문제