is it possible to use a function to

  • From: "Duret, Kathy" <kduret@xxxxxxxxxxxxxxxxxxxx>
  • To: "Oracle L (E-mail)" <oracle-l@xxxxxxxxxxxxx>
  • Date: Thu, 24 Feb 2005 17:13:39 -0600

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 information and reserve the 
right to publish or disclose any information you share with us.



--
//www.freelists.org/webpage/oracle-l

Other related posts: