繁体   English   中英

功能中的Oracle临时存储

[英]Oracle Temporary Storage Within a Function

假设我有一个函数,需要在其中执行多个操作,所有这些操作都取决于一个查询的结果。 我已经找到的所有内容都表明我需要在过程之外定义一个临时表,这是我不想做的。

我想做以下事情:

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM