如何使用 OracleDataReader 将 PL/SQL 查询的输出获取到我的代码中
我已打开服务器输出 并尝试像这样读取输出 但总是说没有输出
ConnectDB();
OracleCommand command1 = conn.CreateCommand();
command1.CommandText = "begin dbms_output.put_line('Output'); end;";
command1.CommandType = CommandType.Text;
OracleDataReader dr = command1.ExecuteReader();
if (dr.HasRows)
{
while(dr.Read())
{
string str = dr[0].ToString();
MessageBox.Show(str);
}
}
else
MessageBox.Show("No output");
conn.Close();
您可以尝试执行查询,例如
using OracleCommand command = conn.CreateCommand();
command.CommandText =
@"select 'Output'
from Dual";
using reader = command.ExecureReader();
if (reader.Read())
MessageBox.Show(Convert.ToString(reader[0]));
else
MessageBox.Show("No output");