使用System.Data.OracleClient連線Oracle執行指令,發現以下的程式寫法會引發奇怪的錯誤:

using (OracleConnection cn = new OracleConnection(cnStr))
{
    cn.Open();
    OracleCommand cmd = new OracleCommand(@"
begin
update myJobQueue set SendFlag = 'X' where JobId = 'XXX';
update myJobQueue set SendFlag = 'D' where JobId = 'ZZZ';
end;
", cn);
    cmd.ExecuteNonQuery();
    cn.Close();
}

ORA-06550: line 1, column 1:
PLS-00103: Encountered the symbol "" when expecting one of the following:

  begin case declare exit for function goto if loop mod null
  package pragma procedure raise return select separate type
  update while with <an identifier>
  <a double-quoted delimited-identifier> <a bind variable> <<
  form table call close current define delete fetch lock insert
  open rollback savepoint set sql execute commit forall merge
  library OPERATOR_ <a single-quoted SQL string> pipe

Oracle抱怨遇到**空字串**??

指令非常單純,看不出任何可疑之處! 不意外地,將指令文字Copy到Toad或其他Oracle Client程式測試,都可以成功執行。

幾經推敲,終於找出原因來,原來錯誤是字串夾帶的換行符號所引起的(這讓我想起上次在SSMS也有類似遭遇)。測試結果,對字串來個Replace("\r", ""),只留下\n,問題就可以排除囉!


Comments

Be the first to post a comment

Post a comment


81 - 65 =