在VB.NET中使用dbms_output.get_line

| 我有一些存储过程要执行,使用“ 0”将数据放入输出缓冲区。 我知道我需要使用ѭ1来检索该输出。 我正在使用ѭ2来避免Oracle部署的麻烦。 那么我下面的代码在做什么呢?
Dim cmdSproc As OracleCommand = cnOracle.CreateCommand()
Dim strOracle As New OracleString()
Dim opaLine As New OracleParameter(\"lineOut\", OracleType.VarChar, 255)
opaLine.Direction = ParameterDirection.Output
Dim opaStatus As New OracleParameter(\"status\", 0)
cmdSproc.CommandText = \"begin dbms_output.get_line(:lineOut,:status); end;\"
cmdSproc.Parameters.Add(opaLine)
cmdSproc.Parameters.Add(opaStatus)

Dim strOutput As String = \"\"
strOracle = \"0\"
Try
   While strOracle = \"0\"
      cmdSproc.ExecuteOracleNonQuery(strOracle)
      strOutput = strOutput & strOracle.ToString() & vbNewLine
   End While
Catch ex As Exception
   MsgBox(ex.Message)
End Try
    
已邀请:
在vb.net中,SKINDER朋友的代码格式如下...共享的thnxs
Sub _showDbms() 
            Dim c As New OracleCommand()
            c.Connection = frmMain._cnn
            With c
                .CommandType = CommandType.Text
                .CommandText = \"begin dbms_output.get_line(:line, :status); end;\"
                .Parameters.Add(New OracleParameter(\"line\", OracleDbType.Varchar2)).Size = 32000
                .Parameters(\"line\").Direction = ParameterDirection.Output
                .Parameters.Add(New OracleParameter(\"status\", OracleDbType.Int32))
                .Parameters(\"status\").Direction = ParameterDirection.Output
            End With
            c.ExecuteNonQuery()
            If c.Parameters(\"line\").Value IsNot DBNull.Value Then
                MsgBox(c.Parameters(\"line\").Value.ToString)
            End If
    End Sub 
    
这是我的工作方式:(在这里找到)
Dim cmdGetOutput As New OracleCommand(\"declare \" & _
    \" l_line varchar2(255); \" & _
    \" l_done number; \" & _
    \" l_buffer long; \" & _
    \"begin \" & _
    \" loop \" & _
    \" exit when length(l_buffer)+255 > :maxbytes OR l_done =1; \" & _
    \" dbms_output.get_line( l_line, l_done ); \" & _
    \" l_buffer := l_buffer || l_line || chr(10); \" & _
    \" end loop; \" & _
    \" :done := l_done; \" & _
    \" :buffer := l_buffer; \" & _
    \"end;\", cnOracle)
cmdGetOutput.Parameters.Add(\"maxbytes\", OracleType.Int16)
cmdGetOutput.Parameters(\"maxbytes\").Value = 32000
cmdGetOutput.Parameters.Add(\"done\", OracleType.Int16)
cmdGetOutput.Parameters(\"done\").Direction = ParameterDirection.Output
cmdGetOutput.Parameters.Add(\"buffer\", OracleType.LongVarChar, 32000)
cmdGetOutput.Parameters(\"buffer\").Direction = ParameterDirection.Output

Dim strOutput As String = \"\"
Dim intStatus As Integer = 0
Try
   While True
      cmdGetOutput.ExecuteNonQuery()
      strOutput = strOutput & cmdGetOutput.Parameters(\"buffer\").Value & vbNewLine
      If cmdGetOutput.Parameters(\"done\").Value = 1 Then
         Exit While
      End If
   End While
Catch ex As Exception
   MsgBox(ex.Message)
Finally
   MsgBox(strOutput)
   cnOracle.Close()
End Try
    
在C#中,我正在使用下一个方法:
    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;
    }
    

要回复问题请先登录注册