日期:2014-05-18  浏览次数:20915 次

C# Oracle 执行多条 insert 问题
C# code
        private void EXT_SQL_TEST()
        {
            string strMsg = "OK";

            try
            {
                    StringBuilder strSql = new StringBuilder();

                    strSql.Append(" BEGIN; ");
                    strSql.Append(" INSERT INTO Order_Main (UUID) values (6); ");
                    strSql.Append(" INSERT INTO Order_Main (UUID) values (7); ");
                    strSql.Append(" INSERT INTO Order_Main (UUID) values (8); ");
                    strSql.Append(" INSERT INTO Order_Main (UUID) values (9); ");
                    strSql.Append(" END; ");


                OracleHelper.ExecuteNonQuery(oradb, CommandType.Text, strSql.ToString());
            }
            catch (Exception ex)
            {
                strMsg = ex.ToString();
            }
            if (strMsg != "OK")
            {
                MessageBox.Show(strMsg);
            }
            else
            {

            }
        }



错误提示 
C# code
System.Data.OracleClient.OracleException: ORA-06550: 第 1 行, 第 7 列: 
PLS-00103: 出现符号 \";\"在需要下列之一时:
 begin case declare exit for
   goto if loop mod null pragma raise return select update while
   with <an identifier> <a double-quoted delimited-identifier>
   <a bind variable> << close current delete fetch lock insert
   open rollback savepoint set sql execute commit forall merge
   <a single-quoted SQL string> pipe
符号 \"exit\" 被替换为 \";\" 后继续。
   at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)
   at System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()


查询网上有个帖子 说类似的问题。
http://blog.csdn.net/wyzxg/article/details/4761589
http://topic.csdn.net/t/20040607/15/3070702.html

难道这个问题用MS的 System.Data.OracleClient;真的解决不了吗?

------解决方案--------------------
begin后需要加分号吗?
------解决方案--------------------

你的StringBuilder 拼接出来的东西到最后你知道是什么吗?
你拿到 PLSQL里面能执行吗?

明显的SQL 问题

------解决方案--------------------
begin后面不能有分号, 换用oracle 提供的provider试试。