摘要:[ASP.NET]解決 OracleClient 出現 Encountered the symbol "" 錯誤訊息
在使用 String 組 Begin End + 多段 異動 SQL 做交易時,
大概情境是......:
String l_strSql =
String.Format(@ "Begin
Delete From TableB Where fKey ='{0}' "
,"20131015018" );
for ( int i=0; i< l_list.Count ; i++ )
{
MyItem l_thisItem = l_list[i];
String l_strTemp =String.Format( @" Update TableA Set fName = '{0}' Where fID = '{1}' "
,l_thisItem.fName
,l_thisItem.fID ) ;
l_strSql += l_strTemp ;
}
l_strSql +="End; ";
在執行ExcuteNonQuery 時發生錯誤,訊息如下
ORA-06550: line 1, column 6:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <ID>
<外加雙引號的分界 ID> <連結變數> << close current
delete fetch lock insert open rollback savepoint set sql
execute commit forall merge pipe
The symbol "" was ignored.
把SQL字串拿到 PL/SQL Dev 上執行很正常....
查了SQL字串許久,最後發現原來是溢出字元的問題!!
SQL 字串中 含有 /r 換行字元
把它置換掉即可 >> l_strSql = l_strSql .Replace("/r","");