SQL中的 for update

mirageTF 2003-05-26 06:21:14
请教关于 for update 在SQL语句中的作用.
...全文
40 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiezhi 2003-05-26
  • 打赏
  • 举报
回复

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.
COMMIT;
END;
/
jiezhi 2003-05-26
  • 打赏
  • 举报
回复

Specify FOR UPDATE to allow a subquery, primary key, object, or rowid materialized
view to be updated. When used in conjunction with Advanced Replication, these
updates will be propagated to the master.
see:
Oracle9i Replication
BlueskyWide 2003-05-26
  • 打赏
  • 举报
回复
参考:
update your_tb set your_fd='mirageTF' where your_fd like 'miage%';

17,377

社区成员

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

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