【问题标题】:Oracle for loop queryOracle for 循环查询
【发布时间】:2019-07-11 06:41:06
【问题描述】:

如何在 Oracle PL/SQL 中执行以下操作:

BEGIN
  FOR id IN ( 10,200,30,43,5444,6 ) 
    LOOP
        process_the_record ( id );
END LOOP;
END;    

因为这似乎对我不起作用。

我基本上需要遍历这些数字中的每一个并将每个数字传递到过程中,process_the_record (id)。

【问题讨论】:

    标签: oracle plsql


    【解决方案1】:

    你可以使用一个集合——你只需要调用process_the_record而不是dbms_output.put_line

    SQL> declare
      2    type num_arr is table of number;
      3    l_ids num_arr := num_arr( 10, 200, 30, 32, 5444, 6 );
      4  begin
      5    for i in 1 .. l_ids.count
      6    loop
      7      dbms_output.put_line( l_ids(i) );
      8    end loop;
      9  end;
     10  /
    10
    200
    30
    32
    5444
    6
    

    【讨论】:

      【解决方案2】:

      查看可变数组条目here。这些数字会改变吗?似乎这是一种尴尬的做事方式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多