如何在带有嵌套表的语句中使用

时间:2015-11-02 23:57:12

标签: sql oracle plsql

嘿,我有一个函数,函数的一部分是确保所选值在varchar2s的传入表中。首先,我声明一个varchar2表类型。

create or replace type Varchar2Table is table of varchar2(200)

然后我有了接受嵌套表参数的函数,并在它们上面有一个select语句。

function SelectPeople(inputNames Varchar2Table) return People
begin
--stuff
select * from person_table where name in inputNames; --line of interest
--more stuff
end;

这似乎不起作用,我收到以下错误:

  

ORA-00932:数据类型不一致:得到了预期的NUMBER   ENGSPL5.VARCHAR2TABLE

有什么建议吗?

1 个答案:

答案 0 :(得分:3)

TABLE运算符允许在SQL语句中使用嵌套表。该函数还缺少ISINTO

create or replace type Varchar2Table is table of varchar2(200);

create table person_table(id number, name varchar2(100));

create or replace function SelectPeople(inputNames Varchar2Table) return number
is --Missing "IS".
    type numberTable is table of number; --Need a collection to store results.
    numbers numberTable;
begin
    select id
    bulk collect into numbers --Missing "INTO".
    from person_table
    where name in (select column_value from table(inputNames)); --Missing "TABLE".
    --Alternatively a multiset condition can be used.
    --where name member of inputNames;

    --Dummy return value to make the function compile.
    return 1;
end;
/