2015-11-02 28 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謝謝,我更新了我的答案。 –