获得匿名PL / SQL的结果

时间:2014-03-17 23:04:44

标签: c# plsql

我正在尝试在C#中执行匿名PL / SQL。这是我的代码:

var requete = " DECLARE \n";
requete = requete + "type cursor_out is ref cursor; \n";
requete = requete + " cur cursor_out; \n";
requete = requete + "person_row XXX%rowtype; \n";
requete = requete + "procedure Select_Proc(result out cursor_out) is \n";
requete = requete + " begin \n";
requete = requete + "open result for select * from XXX \n";
requete = requete + "end; \n";
requete = requete + "begin \n";
requete = requete + "Select_Proc(cur); \n";
requete = requete + "loop \n";
requete = requete + "fetch cur into person_row; \n";
requete = requete + "exit when cur%notfound; \n";

requete = requete + "end loop; \n";
requete = requete + "close cur; \n";
requete = requete + "end;";

var oc = new OracleConnection(connectionString);
oc.Open();
var cmd = new OracleCommand
{
    Connection = oc,
    CommandText = requete,
    CommandType = CommandType.StoredProcedure

};
OracleDataReader odr = cmd.ExecuteReader();

当我在SqlPlus中运行一些PLSQL脚本时,它会运行(我添加了“/”),但在C#中我遇到了类似这样的错误:

  

PLS-00103:遇到符号“;”期待以下之一:

1 个答案:

答案 0 :(得分:2)

删除PL / SQL代码中最后;后的end

SQL * PLUS使用;(和/)来分隔命令。使用ODBC时,您一次只能发送一个命令,因此不需要;,甚至会导致异常。