我有一个表,其中包含最大值,需要由多个程序获取和设置。如何获取旧值并在C#中更新新内容时,如何锁定表格一段时间?换句话说:是否可以使用ADO.NET锁定Oracle 10g数据库表?
string sql = "lock table MaxValueTable in exclusive mode";
using (DbCommand cmd = cnctn.CreateCommand())
{
cmd.CommandText = sql;
// execute command somehow!!
}
maxValue = GetMaxValue();
SetMaxValue(maxValue + X);
sql = "lock table MaxValueTable in share mode";
using (DbCommand cmd = cnctn.CreateCommand())
{
cmd.CommandText = sql;
// execute command somehow!!
}
广东话”你用Oracle序列呢?它会处理同步你。 – 2010-03-05 11:54:14
@Peter郎。完美。一个序列也许马蒂可以解释他为什么不这样做 – Guru 2010-03-05 11:56:53
@马蒂 - 彼得的建议是健全的 - 看看http://www.techonthenet.com/oracle/sequences.php – RichardOD 2010-03-05 11:57:22