ORACLE 10G
下面SQL由程序自动生成,个数是不确定的。
update tb set abc='123' where id=1
update tb set abc='12sdf3' where id=12
update tb set abc='qwe' where id=221
update tb set abc='1s' where id=35351
.....怎么写个东东访问一次数据库一次性搞定?

解决方案 »

  1.   

    1. 很简单啊,写个存储过程,将这些SQL语句以数据的形式传到存储过程中。
    2. 在存储过程中使用循环读出每条SQL语句,然后使用动态SQL来执行。最后commit
      

  2.   

    参考下面这个逻辑,一次提交
    String sql = "update ADJUST set alpha=@alpha where systemMark='a' and orderid=@orderid";
    OracleTransaction tx = new OracleTransaction();
    tx.begin();
    OracleCommand = new OracleCommand(conn, sql);
    for (int i = 0; i<10000; i++)
    {
      OracleParameter[] params = new OracleParameter[2];
      params[0] = cmd.Parameters.Add(..)
      params[1] = cmd.Parameters.Add(..)
      rowsAffected = cmd.ExecuteNonQuery();
      cmd.Parameters.Clear();
      if ((i+1) % 1000 ==0)
      {
      tx.commit();
      tx.begin();
      }
    }
    tx.commit();
      

  3.   

    怎么写啊?SQL之间是用“;”分开的,谢谢