记录锁定问题

arclala 2003-03-18 08:45:35
在读取表的某一行记录时,锁定这一行,直到我更新了这行的记录后再解锁,不知怎样实现?
...全文
45 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
beckhambobo 2003-03-18
  • 打赏
  • 举报
回复
DECLARE
-- Number of credits to add to each student's total
v_NumCredits classes.num_credits%TYPE;

-- This cursor will select only those students who are currently
-- registered for HIS 101.
CURSOR c_RegisteredStudents IS
SELECT *
FROM students
WHERE id IN (SELECT student_id
FROM registered_students
WHERE department= 'HIS'
AND course = 101)
FOR UPDATE OF current_credits;

BEGIN
-- Set up the cursor fetch loop.
FOR v_StudentInfo IN c_RegisteredStudents LOOP
-- Determine the number of credits for HIS 101.
SELECT num_credits
INTO v_NumCredits
FROM classes
WHERE department = 'HIS'
AND course = 101;

-- Update the row we just retrieved from the cursor.
UPDATE students
SET current_credits = current_credits + v_NumCredits
WHERE CURRENT OF c_RegisteredStudents;
END LOOP;

-- Commit our work, and release the lock.
COMMIT;
END;
/

注意:在commit前,把所有dml语句操作,遇到事务处理就马上释放任何锁
lianhg 2003-03-18
  • 打赏
  • 举报
回复
Dim objRe As New ADODB.Recordset
objRe.Open "select fld from tbl", , , adLockPessimistic
hrb_qiuyb 2003-03-18
  • 打赏
  • 举报
回复
select ... for update;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧