在实际开发的时候有的时候希望一次执行多句SQL语句,又不想使用Transcation的话,可以直接将多句SQL语句拼接起来。例如:
var sql = "Begin " +
"Update tabUser Set UserName = :UserName Where UserId = :UserId; " +
"Update tabUser Set UserPassword = :UserPassword Where UserId = :UserId And UserPassword <> :UserPassword; " +
"End; ";
var param = new Oracle.DataAccess.Client.OracleParameter[]
{
new OracleParameter(":UserId",OracleDbType.Int32){Value = 1},
new OracleParameter(":UserName",OracleDbType.Varchar2){Value = "name"},
new OracleParameter(":UserPassword",OracleDbType.Varchar2){Value = "password"}
};
然后将SQL语句和参数赋给OracleCommand执行就可以了。重点在于使用Begin和End包裹,声明是一次多语句执行。
时间: 2024-10-24 09:33:35