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;
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