Selecting Values from Oracle Table Variable / Array?(从 Oracle 表变量/数组中选择值?)
问题描述
继我的上一个问题之后(Oracle PL/SQL 中的表变量?)...
Following on from my last question (Table Variables in Oracle PL/SQL?)...
一旦数组/表中有值,如何将它们再次取出?最好使用 select 语句或类似的东西?
Once you have values in an array/table, how do you get them back out again? Preferably using a select statement or something of the like?
这是我到目前为止所得到的:
Here's what I've got so far:
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() 输出它们,但我希望得到一个结果集,就像我从任何其他表中选择一样.
I know I can output them using dbms_output.putline(), but I'm hoping to get a result set like I would from selecting from any other table.
提前致谢,马特
推荐答案
您可能需要一个全局临时表.
You might need a GLOBAL TEMPORARY TABLE.
在 Oracle 中,这些创建一次,然后在调用时数据对您的会话来说是私有的.
In Oracle these are created once and then when invoked the data is private to your session.
Oracle 文档链接
尝试这样的事情...
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;
/
这篇关于从 Oracle 表变量/数组中选择值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Oracle 表变量/数组中选择值?


- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01