【发布时间】:2011-04-27 23:32:35
【问题描述】:
我正在使用 Oracle 命令 dbms_output.get_line 从存储过程中检索输出。一旦我的代码运行命令,我将通过一个 32000 字节长的缓冲区字符串检索结果。
这个字符串不可避免地会有 Oracle 换行符 (chr(10) 和 chr(13)) 我想用 Environment.NewLine 替换所以我可以在标准的 Winforms 文本框中显示输出。
这是我一直在使用的代码 - 我不记得我现在确切地从哪里获得了 Oracle 命令,但如果我找到它,我会添加链接。
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 List(Of String) = New List(Of String)
Dim intStatus As Integer = 0
Try
While True
cmdGetOutput.ExecuteNonQuery()
strOutput.Add(cmdGetOutput.Parameters("buffer").Value)
If cmdGetOutput.Parameters("done").Value = 1 Then
Exit While
End If
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
For ixLines as Integer = 0 to strOutput.Count - 1
txtOutput.Text = txtOutput.Text & strOutput(ixLines)
Next
End Try
当我运行这个时,txtOutput 将在应该换行的地方有方框字符。
谢谢大家的帮助!
【问题讨论】:
标签: vb.net winforms oracle oracle9i