假设我有一个我需要执行多个操作的功能,所有这些都取决于一个查询的结果。我能找到的一切都表明我需要在过程之外定义一个临时表,而我不想做。

我想做以下操作:

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;

该语法不起作用。 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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top