These are the examples to update table data using loop in PL SQL.
BEGIN FOR I IN (
SELECT A.EMPLID, A.ACAD_PROG
FROM PS_ACAD_PROG A , ps_UOD_STU_ADV_UPL B
WHERE ( A.EFFDT =
(SELECT MAX(A_ED.EFFDT) FROM PS_ACAD_PROG A_ED
WHERE A.EMPLID = A_ED.EMPLID
AND A.ACAD_CAREER = A_ED.ACAD_CAREER
AND A.STDNT_CAR_NBR = A_ED.STDNT_CAR_NBR
AND A_ED.EFFDT <= SYSDATE)
AND A.EFFSEQ =
(SELECT MAX(A_ES.EFFSEQ) FROM PS_ACAD_PROG A_ES
WHERE A.EMPLID = A_ES.EMPLID
AND A.ACAD_CAREER = A_ES.ACAD_CAREER
AND A.STDNT_CAR_NBR = A_ES.STDNT_CAR_NBR
AND A.EFFDT = A_ES.EFFDT))
AND A.EMPLID = B.EMPLID
AND B.OPRID = 'dar.tech2' ) LOOP
UPDATE ps_UOD_STU_ADV_UPL D
SET D.acad_prog1 = I.acad_prog
WHERE D.EMPLID = I.EMPLID;
END LOOP;
END;
------------------------------------------------------------------------------------------
BEGIN
FOR I IN (
SELECT COUNT(A.EMPLID) AS TOT, A.CLASS_NBR, A.STRM
FROM ps_stdnt_enrl A
WHERE A.strm = '2241'
AND A.STDNT_ENRL_STATUS = 'E'
GROUP BY A.CLASS_NBR, A.STRM
) LOOP
UPDATE PS_CLASS_TBL K
SET K.ENRL_TOT = I.TOT
WHERE K.strm = I.STRM
AND K.class_nbr = I.CLASS_NBR;
END LOOP;
COMMIT; -- Commit changes after the loop
EXCEPTION
WHEN OTHERS THEN
RAISE; -- Handle exceptions if needed
END;