您太循环游标中返回的记录/行;你不能像这样引用游标本身:
CREATE OR REPLACE PROCEDURE proc
IS
result varchar(50);
cursor c2 is
SELECT note
FROM student;
BEGIN
FOR r2 IN c2 LOOP
IF r2.note = 5 THEN -- IN would also work but doesn't add anything
result := 'contains 5';
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE(result);
END;
/
但是,如果您只是测试是否存在任何具有值的记录,5
那么您不需要游标:
CREATE OR REPLACE PROCEDURE proc
IS
result varchar(50);
BEGIN
SELECT max('contains 5')
INTO result
FROM student
WHERE note = 5;
DBMS_OUTPUT.PUT_LINE(result);
END;
/
如果有任何五行,您将获得'contains 5'
字符串;如果没有,你会得到null
。如果max()
表中有零个或多个匹配记录,则停止抛出异常。