【问题标题】:select inside loop oracle选择内部循环oracle
【发布时间】:2014-05-02 12:12:49
【问题描述】:

我编写了一个存储过程,其中包含一个循环内的查询。 此查询将记录设置为 RECORD 类型的自定义数据类型,例如

TYPE finalrecord
IS
  RECORD
  (
    corh           VARCHAR2(1),
    myspissueid    NUMBER(10),
    mypkey         VARCHAR2(10),
    mycreated      DATE,
    myprevstepname VARCHAR2(10),
    mystepname     VARCHAR2(10),
    mystorypoints  NUMBER(2) );

  myfinalrecord finalrecord;

for 循环是这样的

for vh in (select * from table1 where abc=3)
loop

select steps.current_or_history,
    steps.issueid,
    steps.pkey,
    steps.created,
    steps.prev_step_name,
    steps.step_name,
    steps.story_points

from steps where column1 = 'xyz' and column2=vh.column2;


end loop;

每次执行内部循环时,SELECT 语句都会返回多条记录。我想将此记录添加到主变量(作为集合..但可变数组或嵌套表或关联数组)并将该变量作为存储过程的输出返回。

有什么想法吗?

【问题讨论】:

    标签: oracle stored-procedures plsql


    【解决方案1】:
    declare
      type t is table of finalrecord;
      my_table t;
    begin
      for vh in (select * from table1 where abc = 3) loop
    
        execute immediate 'select finalrecord(steps.current_or_history,
            steps.issueid,
            steps.pkey,
            steps.created,
            steps.prev_step_name,
            steps.step_name,
            steps.story_points)
    
        from steps where column1 = ''xyz'' and column2=vh.column2' bulk
                          collect
          into my_table;
    
      end loop;
    end;
    

    如果可行,你可以试试这个,你也可以创建过程...

    【讨论】:

    • 我如何返回这个“my_table”?我的意思是这个过程的返回类型应该是这个“my_table”
    猜你喜欢
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 2012-02-26
    • 2021-02-04
    • 2020-08-27
    • 2012-08-20
    • 2017-05-29
    • 1970-01-01
    相关资源
    最近更新 更多