Kursor selalu dibuka pada pernyataan SELECT. Tidak ada cara, sejauh yang saya ketahui, untuk membuka kursor pada FOR
lingkaran.
Sepertinya Anda benar-benar ingin membuat pernyataan SELECT secara dinamis. Saya menyarankan sesuatu seperti berikut:
PROCEDURE p_get_xxx(p_id IN VARCHAR2, p_cur_result OUT SYSREFCURSOR)
AS
l_array schema_name.t_array;
strSelect_statement VARCHAR2(4000);
BEGIN
l_array := split_string(p_id);
-- Set up the basics of the SELECT statement
strSelect_statement := 'SELECT * FROM SOME_TABLE WHERE ID IN (';
FOR i IN l_array.FIRST..l_array.LAST LOOP
strSelect_statement := strSelect_statement ||
'''' || l_array(i) || ''',';
END LOOP;
-- Get rid of the unwanted trailing comma
strSelect_statement := SUBSTR(strSelect_statement, 1,
LENGTH(strSelect_statement)-1);
-- Add a right parentheses to close the IN list
strSelect_statement := strSelect_statement || ')';
-- Open the cursor
OPEN p_cur_result FOR strSelect_statement;
END p_get_xxx;
Semoga berhasil.