我正在用光标挣扎,尝试了不同的版本而没有运气,并决定在这里寻求帮助。如何使IF条件工作?我必须计算一些东西,然后检查这个数是否大于10,然后删除一些东西。如何将计数(*)传递给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;
答案 0 :(得分:1)
声明:
COUNT_VAR NUMBER(38);
身体:
SELECT COUNT(*) INTO COUNT_VAR
FROM SOME_TABLE
WHERE SOME_DATE = STATUSCHANGEDDATE_ AND ....;
IF COUNT_VAR = 10 THEN
DELETE * FROM SOME_TABLE2 WHERE SOME_CONDITION2;
END IF;