2015-11-02 31 views
1

嘿,我有一个函数,其中的一部分功能是确保所选值位于传入的varchar2s表中。要开始我像这样声明一个varchar2表类型。如何在嵌套表中使用声明

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

然后我有接受嵌套表参数并有一个选择语句的函数。

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

这似乎并没有工作,虽然,我得到以下错误:

ORA-00932: inconsistent datatypes: expected NUMBER got ENGSPL5.VARCHAR2TABLE

有什么建议?

+1

您是否在此处收到错误消息?如果是这样,什么?如果不是,会发生什么? – Dan

+0

错误是“ORA-00932:不一致的数据类型:预计NUMBER得到了ENGSPL5.VARCHAR2TABLE”。 不知道为什么它说,当我传递在双方varchar2虽然期望的数字。 – Coat

+0

尽管您并未传递VARCHAR2,但您要求它将VARCHAR2列转换为用户定义的类型,但它没有超载。我认为NUMBER一定是它的默认猜测。 –

回答

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; 
/
+1

你也可以使用'WHERE name name'inputNames' –

+0

@WernfriedDomscheit谢谢,我更新了我的答案。 –