我正在努力使用光标,尝试了不同的版本但没有运气,并决定在这里寻求帮助。如何使 IF 条件起作用?我必须计算一些东西,然后检查这个计数是否大于 10,然后删除一些东西。如何将 count(*) 传递给 IF 条件然后执行某些操作?提前致谢。
DECLARE
CURSOR MY_CURSOR
IS
SELECT CSH.STATUSCHANGEDDATE AS STATUSCHANGEDDATE_, CSH.CUSTOMER AS CUSTOMER_ from CUSTOMER_STATUSES csh WHERE
csh.STATUSCHANGEDATE>SOME_DATE AND CSH.STATUS = 'X_STATUS'
MY_RECORD MY_CURSOR%ROWTYPE;
BEGIN
OPEN MY_CURSOR;
LOOP
FETCH MY_CURSOR INTO MY_RECORD;
EXIT
WHEN MY_CURSOR%NOTFOUND;
SELECT COUNT(*) FROM SOME_TABLE WHERE SOME_DATE = STATUSCHANGEDDATE_ AND ....
iF ABOVE_COUNT = 10 THEN
DELETE * FROM SOME_TABLE2 WHERE SOME_CONDITION2
ELSE
END IF
END LOOP;
END LOOP;
COMMIT;
END;