我正在尝试从进行查询、处理字段并返回集合的函数中获取结果。
如果我对函数进行查询并单独执行,它会在大约 10 分钟内返回,具体取决于我输入的参数。如果我将相同的参数传递给函数,它会继续处理,45 分钟后我无法得到任何结果。
查询后,我只有几个 if 用于检查零值或高于其他值的值。
我认为问题在于我传递了一些参数 null 或空白,这会使查询崩溃。这是我的问题:
我有一个类型:
CREATE OR REPLACE TYPE TypeForFunction is OBJECT (
-- all my fields here
)
/
然后做一个集合:
CREATE OR REPLACE TYPE TypeForFunctionTable AS
TABLE OF TypeForFunction
/
然后我的功能是这样的:
CREATE OR REPLACE FUNCTION MyFunction
(
/* here I have five parameters and in the case that the query crashes,
two of them I'm trying to pass blank or null */
COL in varchar2, -- This I pass a valid value
INDEX in number, -- same here
REF in varchar2, -- This one I'm trying to pass Blank ('') or Null and i
get no result no matter which one I pass.
P in varchar2,
BLOQ in varchar2 -- Same null or blank here
) RETURN TypeForFunctionTable
IS
result_table TypeForFunctionTable;
i integer := 0;
begin
select
TypeForFunction(
/* Here I have some subquerys that I use the parameters null which
I use the same way as parameter REF. Like: */
and (MyTable.FieldP = P or P is null)
and (MyTable.FielBloq = BLOQ or BLOQ is null)
) BULK COLLECT into result_table
from
myTables
where
-- here I have a clause like
(MyTable.FieldREF = REF or REF is null)
;
For i in 1..result_table.count loop
/* Here I have some if's, but nothing to crash the query like it happens.
Things like: */
if MyVar > 0 then
COL = REF;
INDEX = INDEX + 100;
end loop;
return result_table;
end MyFunction;
/
要调用我尝试的函数:
select * from table(MyFunction('59', 1, '', 'IV18', ''));
也试试:
select * from table(MyFunction('59', 1, Null, 'IV18', Null));
无论如何,我得到相同的结果,函数在 45 分钟后不会返回或给出任何错误。
有没有更好的方法来处理我可能会或可能不会传递值的参数?