cau 5
CREATE OR REPLACE PROCEDURE P_CURSOR
IS
CURSOR TEO IS SELECT MSPB FROM PHONGBAN;
SONHANV INT;
MS0PB PHONGBAN.MSPB%TYPE;
FUNCTION F_DEMNV(MAPHONG IN PHONGBAN.MSPB)RETURN INT
IS
SONV INT;
BEGIN
SELECT COUNT(NV.PHG) INTO SONV FROM NHANVIEN NV,PHONGBAN PB WHERE NV.PHG=PB.MSPB AND PB.MSPB=MAPHONG;
RETURN SONV;
END F_DEMNV;
BEGIN
OPEN TEO;
LOOP
FETCH TEO INTO MSOPB;
SONHANV:=F_DEMNV(MSOPB);
EXIT WHEN TEO%NOTFOUND;
UPDATE PHONGBAN
SET SONV=SONHANV
WHERE MSPB=MSOPB;
END LOOP;
CLOSE TEO;
END P_CURSOR;
-------GOI THUC THI------------
EXECUTE P_CURSOR
Bạn đang đọc truyện trên: AzTruyen.Top