【发布时间】:2018-08-21 21:06:44
【问题描述】:
我有以下 oracle 函数,它有 num_list 作为逗号分隔列表的输入,然后检查此列表中的数字是否存在于某个表中:
create or replace FUNCTION get_num_exist (num_list varchar2,separator varchar2)
RETURN nbs PIPELINED
as
row_type nb;
begin
with numbers as
(select regexp_substr(num_list,'[^'||separator||']+', 1, level)num_
from dual
connect by regexp_substr(num_list, '[^'||separator||']+', 1, level) is not null)
for r_row in (select * from numbers
where num_ in (select phone_number
from phone_numbers) )
loop
PIPE ROW(nb(r_row.num_));
end loop;
return;
end;
但它在 for 循环级别给出了语法错误。
任何帮助将不胜感激。
【问题讨论】:
-
您已经使用 for 循环拆分了 CTE 和 CTE 中的选择,这是行不通的。 with 子句必须与 select 一起使用 - 尽管此函数的真正目的尚不清楚。如果您能提供更多关于您想要实现的目标的详细信息,这可能会有所帮助,
-
你的 with 子句大概属于游标吧?如果是这样,它应该是循环光标的一部分,即
for r_row in (with numbers as (...) select * from numbers ... -
@Andrew 我想从 phone_numbers 表中的列表中返回号码。