Tra*_*vis 1 sql oracle function temp-tables
假设我有一个函数,我需要在其中执行多个操作,所有操作都取决于一个查询的结果.我能找到的所有东西都表明我需要在程序之外定义一个临时表,我不想这样做.
我想做类似以下的事情:
create or replace function f_example(
a_input in number
)
return varchar2 is
begin
create local temporary table tempIDs
(
testID number(6, 0)
, testValue number(8,0)
);
//select data from tableFoo that will be overwritten by a_input into tempIDs
//update data in tableFoo with a_input & store old data in another tableFoo field
end f_example;
Run Code Online (Sandbox Code Playgroud)
此语法不起作用.Oracle不允许在函数内部使用"创建".
我不是一个真正的数据库程序员 - 我习惯于使用C#和Java.在这种情况下,我会将我的值存储在方法完成时超出范围的本地数组(或其他)中.在Oracle SQL中是否合法地无法做到这样的事情?
您可以定义PL/SQL记录类型和关联的表类型.然后你可以发一个SELECT...BULK COLLECT填表.
declare
type my_record_type is record (testId number, testvalue number);
type my_table_type is table of my_record_type index by binary_integer;
my_table my_table_type;
begin
select x, y bulk collect into my_table from table_foo;
end;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
631 次 |
| 最近记录: |