【发布时间】:2013-11-07 21:40:34
【问题描述】:
假设我有一个函数,我需要在其中执行多个操作,所有这些操作都取决于一个查询的结果。我能找到的一切都表明我需要在过程之外定义一个临时表,我不想这样做。
我想做如下的事情:
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 和 Java 一样有集合和数组。
-
根据代码示例中的cmets,您根本不需要临时存储,只需执行
update tableFoo set a_field = a_input, another_field = a_field where ... -
我面临的问题(我的示例没有足够清楚地传达)是我需要能够在更新后引用旧值。
标签: sql oracle function temp-tables