Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: is it possible to use a function to
For this kind of thing, I usually build the whole statement and concatenate
my list into it.
But, I think you can do it without the function. Something like ...
select *
from test2
where symbol in (
select distinct
symbol
from test
where ...
)
/
Jon Knight
-----Original Message-----
From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org]
On Behalf Of Duret, Kathy
Sent: Thursday, February 24, 2005 5:14 PM To: Oracle L (E-mail) Subject: is it possible to use a function to
8.1.7.4 Solaris 9
What I want to do is build a In list and feed it to a query:
select * from test2 where
symbol in ( select test_function('IBM') symbol from dual);
One symbol comming out of the function works fine. multiples do not the select test_function('IBM') from dual works just fine.
I cannot get the outer query to work.
What am I missing?
Thanks,
Kathy
CREATE OR REPLACE FUNCTION test_function ( p_symbol in test.symbol%type
) RETURN varchar2
is
v_cur_symbol alias.symbol%type; v_in_list_sql varchar2 (4000); v_symbol alias.symbol%type := upper(p_symbol); cursor symbol_cur is select distinct a1.symbol from test where symbol = v_symbol ) BEGIN
For symbol_recs in symbol_cur
LOOP
v_cur_symbol := symbol_recs.symbol || ',';
v_in_list_sql := rtrim(v_in_list_sql,' ') || v_cur_symbol;
END LOOP;
/* take off last comma */
v_in_list_sql := substr(rtrim(v_in_list_sql,' ')
,1,(length(rtrim(v_in_list_sql,' ')))-1 ) ;
return v_in_list_sql;
EXCEPTION
WHEN No_Data_Found
THEN
return v_in_list_sql;
WHEN OTHERS
THEN
raise_application_error(sqlcode, SUBSTR(SQLERRM,1,100));
end;
This transmission contains information solely for intended recipient and may
be privileged, confidential and/or otherwise protect from disclosure. If
you are not the intended recipient, please contact the sender and delete all
copies of this transmission. This message and/or the materials contained
herein are not an offer to sell, or a solicitation of an offer to buy, any
securities or other instruments. The information has been obtained or
derived from sources believed by us to be reliable, but we do not represent
that it is accurate or complete. Any opinions or estimates contained in
this information constitute our judgment as of this date and are subject to
change without notice. Any information you share with us will be used in
the operation of our business, and we do not request and do not want any
material, nonpublic information. Absent an express prior written agreement,
we are not agreeing to treat any information confidentially and will use any
and all informati
on and reserve the right to publish or disclose any information you share
with us.
--
http://www.freelists.org/webpage/oracle-l
--
http://www.freelists.org/webpage/oracle-l
Received on Thu Feb 24 2005 - 18:42:32 CST