如何调用pl sql函数,该函数以数字表作为1个数字的输入?
我有一个将数字表作为输入的函数:如何调用pl sql函数,该函数以数字表作为1个数字的输入?,sql,oracle,function,plsql,Sql,Oracle,Function,Plsql,我有一个将数字表作为输入的函数: function foo(ids in custom_array)... 其中,自定义_数组是一个数字表 如果只需要传递1个参数,如何从SQL查询调用此函数 我想这应该是这样的 select * from table(foo(123)) 但我猜错了 编辑: 函数的声明如下所示: create or replace function foo(id in custom_array) return tableof2numbers AS mytable ta
function foo(ids in custom_array)...
其中,自定义_数组
是一个数字表
如果只需要传递1个参数,如何从SQL查询调用此函数
我想这应该是这样的
select * from table(foo(123))
但我猜错了
编辑:
函数的声明如下所示:
create or replace function foo(id in custom_array) return
tableof2numbers AS
mytable tableof2numbers;
BEGIN
SELECT cast(
MULTISET (
/*there goes some super secret business logic*/
/*let's say that here we just do smth like this: */
select 123, 123 from dual
/*because this is not so important for this question*/
)
AS tableof2numbers)
INTO
mytable
FROM dual;
RETURN mytable;
其中,tableofnumbers
是另一种自定义类型,其声明与custom_数组
非常相似,但有两个数字
提前感谢 我的例子:
1)类型
create or replace TYPE "TABLE_OF_NUMBER"
AS TABLE OF NUMBER
2)功能
CREATE OR REPLACE FUNCTION foo(
par IN table_of_number)
RETURN NUMBER
IS
BEGIN
RETURN par(1);
END;
3)选择
SELECT foo(table_of_number(123)) FROM dual
如果您的函数返回table,它将类似于
SELECT * FROM TABLE (foo(custom_array(123)))
希望它能有所帮助。我收到这个错误:ORA-06553:PLS-306:调用'foo'时参数的数量或类型错误请显示自定义数组类型和foo的完整定义。
foo
返回什么?您的示例调用似乎暗示它返回一个集合。当然,您可能有一个函数将集合作为输入并返回一个集合作为输出,但也可能您使用了错误的语法来调用它。参数可能应该是foo(custom_array(123))
,但是没有足够的信息来了解完整的select
语句。@我收回我的注释“不,该语法是正确的”-我把foo
误认为是数字类型表的名称。从表中选择*(sys.odcinumberlist(1,2,3,4,5,6,7,8))其中列_值<5将给出1 2 3 4