我试图从pl / sql匿名块中获取vb中的简单hello world输出
据我尝试
Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oradb As String = "Data Source=(DESCRIPTION=" _
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=vmDA2D319)(PORT=1521))" _
+ "(CONNECT_DATA=(SERVICE_NAME=XE)));" _
+ "User Id=hr;Password=hr;"
Dim conn As New OracleConnection(oradb)
conn.Open()
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = "set server output on;" & vbNewLine & "DECLARE" & vbNewLine & "message varchar2(20):= 'Hello, World!'; " & vbNewLine & "BEGIN()" & vbNewLine & "dbms_output.put_line(message);" & vbNewLine & "END;" & vbNewLine & "/"
cmd.CommandType = CommandType.Text
Dim dr As OracleDataReader = cmd.ExecuteReader()
dr.Read()
Label1.Text = dr.ExecuteReader
conn.Dispose()
End Sub
End Class
现在这是我现在被困住的部分。我只想实际在文本框中获取输出。
但我只是想在标签中输出输出,或者首先在消息框中输出。
更新
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oradb As String = "Data Source=(DESCRIPTION=" _
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=vmDA2D319)(PORT=1521))" _
+ "(CONNECT_DATA=(SERVICE_NAME=XE)));" _
+ "User Id=hr;Password=hr;"
Dim conn As New OracleConnection(oradb)
conn.Open()
Dim cmd As New OracleCommand
cmd.CommandText = "set server output on;" & vbNewLine & "DECLARE" & vbNewLine & "return_value VARCHAR2(100) := 'Hello World!';" & vbNewLine & "get_status INTEGER;" & vbNewLine & "BEGIN" & vbNewLine & "DBMS_OUTPUT.GET_LINE (return_value, get_status);" & vbNewLine & "IF get_status = 0" & vbNewLine & "THEN" & vbNewLine & "RETURN return_value;" & vbNewLine & "ELSE" & vbNewLine & "RETURN NULL;" & vbNewLine & "END IF;" & vbNewLine & "END;" & vbNewLine & "/"
cmd.CommandType = CommandType.Text
cmd.Parameters.Add("return_value", OracleDbType.Varchar2, 100)
cmd.Parameters("return_value").Direction = ParameterDirection.Output
cmd.Connection = conn
cmd.ExecuteScalar()
Label1.Text = cmd.Parameters("return_value").Value
conn.Dispose()
End Sub
我在cmd.ExecuteScalar()收到错误 使用ORA-00922:缺少或无效选项