加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从Oracle表变量/数组中选择值?

发布时间:2020-12-12 15:13:28 所属栏目:百科 来源:网络整理
导读:接下来我的最后一个问题( Table Variables in Oracle PL/SQL?)… 一旦你在数组/表中有值,你又怎么把它们重新出来呢?最好使用select语句或类似的东西? 这是我到目前为止 declare type array is table of number index by binary_integer; pidms array;begin
接下来我的最后一个问题( Table Variables in Oracle PL/SQL?)…

一旦你在数组/表中有值,你又怎么把它们重新出来呢?最好使用select语句或类似的东西?

这是我到目前为止

declare
    type array is table of number index by binary_integer;
    pidms array;
begin
    for i in    (
                select distinct sgbstdn_pidm
                from sgbstdn
                where sgbstdn_majr_code_1 = 'HS04'
                and sgbstdn_program_1 = 'HSCOMPH'
                )
    loop
        pidms(pidms.count+1) := i.sgbstdn_pidm;
    end loop;

    select *
    from pidms; --ORACLE DOESN'T LIKE THIS BIT!!!
end;

我知道我可以使用dbms_output.putline()输出它们,但我希望从任何其他表中选择一个结果集.

提前致谢,
马特

您可能需要一个GLOBAL TEMPORARY TABLE.

在Oracle中,这些被创建一次,然后被调用时,数据对你的会话是私有的.

Oracle Documentation Link

尝试这样的东西…

CREATE GLOBAL TEMPORARY TABLE temp_number
   ( number_column   NUMBER( 10,0 )
   )
   ON COMMIT DELETE ROWS;

BEGIN 
   INSERT INTO temp_number
      ( number_column )
      ( select distinct sgbstdn_pidm 
          from sgbstdn 
         where sgbstdn_majr_code_1 = 'HS04' 
           and sgbstdn_program_1 = 'HSCOMPH' 
      ); 

    FOR pidms_rec IN ( SELECT number_column FROM temp_number )
    LOOP 
        -- Do something here
        NULL; 
    END LOOP; 
END; 
/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读