Did you by any chance OVERsimplified it?
Because, if table contents is something like this (i.e. strings in MYCOLUMN
)
SQL> select * from mytable;
MYC
---
abc
def
and you want the function to return a number, then you can't select mycolumn
(which is a string) into a number
datatype local function variable myvar2
. But, you can select some number (such as 1
in my example):
SQL> create or replace function myfunction (myvar in str_tab_t)
2 return number
3 is
4 myvar2 number;
5 begin
6 select 1 into myvar2
7 from mytable
8 where mycolumn in (select * from table(myvar));
9 return myvar2;
10 end;
11 /
Function created.
SQL> select myfunction(str_tab_t('abc')) from dual;
MYFUNCTION(STR_TAB_T('ABC'))
----------------------------
1
SQL>
Or, obviously, return a different datatype:
SQL> create or replace function myfunction (myvar in str_tab_t)
2 return mytable.mycolumn%type
3 is
4 myvar2 mytable.mycolumn%type;
5 begin
6 select mycolumn into myvar2
7 from mytable
8 where mycolumn in (select * from table(myvar));
9 return myvar2;
10 end;
11 /
Function created.
SQL> select myfunction(str_tab_t('abc')) from dual;
MYFUNCTION(STR_TAB_T('ABC'))
-------------------------------------------------------------------------
abc
SQL>