我对语句使用游标:
SELECT NAME FROM STUDENT WHERE ROLL = 1;
我用了:
CURSOR C IS SELECT NAME FROM STUDENT WHERE ROLL = roll;
--roll is a variable I receive via a procedure, and the procedure works fine for the received parameter.
执行此操作后,我可以检索 roll = 1 的所有记录。
现在,我需要检索一个组的记录(可能通过游标),就像:
SELECT NAME FROM STUDENT WHERE ROLL IN (2, 4, 6);
但是 IN 子句中的值只有在运行时才知道。我该怎么做?也就是说,有什么方法可以将参数分配给游标的WHERE子句?
我尝试在游标的声明中使用数组,但弹出一个错误,告诉类似:标准类型不能使用。
我用了:
CURSOR C IS SELECT NAME FROM STUDENT WHERE ROLL IN (rolls);
--rolls is an array initialized with the required roll numbers.