【问题标题】:script PLSQL doesn't execute in c# but ok in oracle脚本 PLSQL 不能在 c# 中执行,但在 oracle 中可以
【发布时间】:2012-10-26 10:46:37
【问题描述】:

我尝试在 C# 中执行此脚本:

declare

  NEW_PAP_OPERATOR_ID number;

  cursor cu_records_a_traiter is
    select *    
      from operator_dossier         d,
           pap_operator_verandering ov,
           pap_verandering          v
     where d.operator_id = ov.operator_id
     and v.cr_info = :v_cr_info;

begin

  for rec_cu in cu_records_a_traiter loop

    /* insert new record */

    INSERT INTO BOOD.PAP_OPERATOR
      (HOOFD_OF_NEVENACTIVITEIT)
    VALUES
      (rec_cu.HOOFD_OF_NEVENACTIVITEIT);

    SELECT BOOD.SEQ_PAP_OPERATOR_ID.CURRVAL
      into NEW_PAP_OPERATOR_ID
      FROM dual;

    /* update with new record*/

    UPDATE Bood.Pap_Operator_Verandering
       SET pap_operator_doel_id   = NEW_PAP_OPERATOR_ID,
           datum_wijziging        = Sysdate,
           gebruiker_wijziging_id = '-549'
     WHERE pap_operator_verandering_id = rec_cu.PAP_OPERATOR_VERANDERING_ID;
  end loop;
end;

没有例外,但脚本没有运行。 如果我在没有 C# 的情况下执行 sql 脚本,它可以工作。 我认为currval NEW_PAP_OPERATOR_ID 有问题 目前我在 c# 中并没有什么特别之处。

C#代码:

try
 {
   OracleCommand command = new OracleCommand("myScript", Connection);

   command.Parameters.Add("v_cr_info", OracleDbType.VarChar, changeRequest, ParameterDirection.Input);
   command.ExecuteNonQuery();

   transaction.Commit();
 }
catch (Exception)
 {
   transaction.Rollback();
   throw;
 }
finally
 {
   Connection.Close();
 }

【问题讨论】:

    标签: c# oraclecommand


    【解决方案1】:

    你没有显示 PROC 参数,你也没有指定你的命令是 PROC

    OracleCommand command = new OracleCommand("myScript", Connection);
    command.CommandType = CommandType.StoredProcedure;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多