我正在尝试使用 PL/SQL 执行以下操作:
- 使用查询获取字符串列表
- 使用 for 循环以列表作为输入进行查询。
到目前为止我有这个:
DECLARE
sub2 varchar2(12);
cursor sub is Select ID_SUBLIN from TABLE 1 group by ID_SUBLIN;
BEGIN
for sub2 in sub LOOP
for inner in (select * from TABLE2 where PARAMETER=sub2.ID_SUBLIN )
loop
DBMS_OUTPUT.PUT_LINE( sub2 );
end loop;
end loop;
END;
/
但是它不起作用。我只迭代 11 个项目列表
提前致谢
最佳答案
您有一些结构性问题和拼写错误。请尝试以下操作:
DECLARE
-- sub2 varchar2(12);
--> record_index "sub2" should exist in "for sub2 in sub", not as variable.
cursor sub is Select ID_SUBLIN from TABLE1 group by ID_SUBLIN;
--TABLE^1 [table name can't contain a space]
BEGIN
for sub2 in sub
loop
for inner in (select * from TABLE2 where PARAMETER=sub2.ID_SUBLIN )
loop
dbms_output.put_line( sub2.ID_SUBLIN ); -- must be as <record_index>.<aColumn>
dbms_output.put_line( inner.parameter );
-- by the way, both of the record_indexes with columns of cursors may be used here.
end loop;
end loop;
END;
/
关于oracle - PL/SQL : For loop for select over a list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53119534/