oracle - PL/SQL : For loop for select over a list

标签 oracle for-loop stored-procedures plsql cursor

我正在尝试使用 PL/SQL 执行以下操作:

  1. 使用查询获取字符串列表
  2. 使用 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/

相关文章:

sql - oracle 将一张表中的多行数据复制到另一张表中

sql - ORACLE:查找具有两列(名称如 ID、NUM)的表的 SQL 语法

stored-procedures - MySQL中如何通过存储过程提交查询?

oracle - ins-20802 - 安装期间 oracle 网络配置助手失败 - centos 7

sql - 在oracle中使用索引与创建索引

c++ - 在基于范围的 for 循环中使用转发引用有什么好处?

java - 创建一个循环,在遇到冒号字符之前返回字符

java - 有2个变量的for循环?

c# - 使用 SQL Server 管理对象将存储过程从一个 SQL Server 2008 复制到另一个 SQL Server 2008

oracle - 如何从存储过程中使用Grails中的输出参数获取返回值?